Download presentation
Presentation is loading. Please wait.
Published byAbbey Fling Modified over 10 years ago
1
Introduction to C# Erick Pranata © Sekolah Tinggi Teknik Surabaya 1
3
» Using: adding libraries to the code. » All of your code will be written in classes. This one is called Program. But think of a class as a segment of code that you give a name to. » Inside of the class called Program there is this code: static void Main(string[] args) { }
4
4 © Sekolah Tinggi Teknik Surabaya
5
5
6
6
7
7
8
8
9
9
10
10 © Sekolah Tinggi Teknik Surabaya
11
» The const keyword is used to modify a declaration of a field or local variable. It specifies that the value of the field or the local variable is constant, which means it cannot be modified. For example: const int x = 0;
12
if (condition) { Statement; } else { Statement; } switch (variable) { case value: Statement; break; case value: Statement; break; default: Statement; break; } Exercise: Develop a program to display category for a student’s grade: A : 100-80 B+: 79 – 75 B: 74 – 70 C+: 69 – 65 C: 64 – 56 D: 55 – 45 E: <45
13
while (condition) { Statement; } do { Statement; } while (condition); for (initializer; condition; increment) { Statement; }
14
void NamaProcedure([TipeData1] Param1,…) { Statement; } Example: void LuasPersegi(int p, int l, ref int luas) { luas = p * l; } Invoking: int luas = 0; int panjang = 5; int lebar = 5 LuasPersegi(panjang, lebar, luas); MessageBox.Show(Convert.toString(Luas));
15
15 © Sekolah Tinggi Teknik Surabaya [TipeData] NamaFunction([TipeData1] Param1,…) { Statement; } Example: String CekGenap(int angka) { if (angka % 2 == 0) { return “Genap”; } else { return “Ganjil”; } Invoking: MessageBox.Show(CekGenap(1));
16
private void button1_Click(object sender, EventArgs e) { MessageBox.Show("Hello world"); }
17
private void button1_Click(object sender, EventArgs e) { string FirstName; FirstName = textBox1.Text; MessageBox.Show(FirstName); }
18
» A Simple Calculator
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.