Ana Sayfa > C#, Programlama > Kısa Sınav – 15

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:

  1. C# String Dizisini String Uzunluğuna Göre Sıralama
  2. Kısa Sınav – 12
  3. Kısa Sınav – 14
  4. Dizi oluşturma ve sıralama
  5. C# String’i Title Case’e (Kelimelerin Baş Harfleri Büyük Gerisi Küçük) Çevirme


  1. Henüz yorum yapılmamış.