1) Instance -> bagian dari instance
2) Static -> bukan bagian dari object
3) Lokal -> dideklarasikan di dalam suatu blok, statement,
for, switch atau using. Sebelum nilai dari variabel lokal dapat
diakses maka variabel ini perlu diberi nilai.
PARAMETER
Variabel yang ditemui di dalam suatu method.
1) Value -> harus diberi nilai awal
2) Output -> tidak boleh diberi nilai awal
3) Reference -> harus diberi nilai awal
OPERATOR
1) Unary -> memiliki 1 buah operand (notasi posfix, notasi prefix)
Notasi Posfix :
static void Main(String[] args)
{
int
i = 5;
while
(i > 0)
{
System.Console.WriteLine(i);
--i;
System.Console.ReadKey();
}
}
Notasi Prefix :
static void Main(String[] args)
{
for
(int i = 5; i > 5; i++)
{
System.Console.WriteLine(i);
System.Console.ReadKey();
}
}
2) Binary -> memiliki 2 buah operand (notifikasi infix)
public void Tambah(int x, out int y, ref int z)
{
x = x * 10;
y = x + 10;
z = x * 100;
}
3) Ternary -> memiliki 2 buah operand , ? dan :
Percabangan biasa :
static void Main(String[] args)
{
int
a = 10;
int
c = 15;
string status = String.Empty;
if
(a > c)
{
status = "nilai a lebih besar
dari c";
}
else
{
status = "nilai a lebih kecil
dari c";
}
System.Console.WriteLine(status);
System.Console.ReadKey();
}
Dengan operator tenary :
static void Main(String[] args)
{
string status = String.Empty;
int
a = 5;
int
c = 6;
status = a > c ? "a lebih besar" : "a lebih kecil";
System.Console.WriteLine(status);
System.Console.ReadKey();
}
0 komentar:
Posting Komentar