Kısa Sınav – 15
Aşağıdaki kod bloğunu çalıştırdığımızda ekran çıktımız nasıl olur?
private static string Degisken = "Ilk Deger";
public static string Test()
{
return Degisken = "Ikinci Degisken";
}
public static void Main(string[] args)
{
Console.WriteLine(Degisken);
Console.WriteLine(Test());
Console.WriteLine(Degisken);
Console.ReadLine();
}
Sorunun doğru cevabı için;
Console çıktısı aşağıdaki gibi olacaktır;
Ilk Deger Ikinci Degisken Ikinci Degisken
MSDN’de (=) operatörü atamalarının nasıl yapıldığını okursanız, yukarıdaki sonuç anlamlı olacaktır.
Aşağıdaki basit örnekte oluşan durum, aslında aynı;
b = a = "engin polat";
Önce a değişkenine engin polat değeri atanacak. Sonra b değişkenine, a değişkeninin değeri atanacaktır.
MSDN’den alıntı : The assignment operator (=) stores the value of its right-hand operand in the storage location, property, or indexer denoted by its left-hand operand and returns the value as its result. The operands must be of the same type (or the right-hand operand must be implicitly convertible to the type of the left-hand operand).
İlgili diğer başlıklar:
Lütfen bana yardımcı olun, ben cok yeniyim hic bir bilgim yok.
Nasıl ve nerden başlamamı önerirdiniz?