Static methodlar
-
Csharp Static methodların kullanılmasıyla ile ilgili kısa bir örnek.1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
using System; using System.Collections.Generic; using System.Text; namespace siniflar { class Program { static void Main(string[] args) { /* Alltaki sinif2 adındaki sinifimizdaki mesaj methodu static olarak * tanımlanmadığı için new kelimesiyle yeni bir tane *sinif türetiyoruz. Ve bu sınıf aracılığıyla methodumuzu çağırıyoruz. */ sinif2 yenisinif = new sinif2(); yenisinif.Mesaj(); // sinif3 yazıp nokta koyarsanız methodun ismini görebilirsiniz. //Çünkü static olarak tanımladık. sinif3.Mesaj(); } } public class sinif2 { public void Mesaj() { Console.WriteLine("Sinif 2 den geldim"); Console.ReadLine(); } } public class sinif3 { public static void Mesaj() { Console.WriteLine("Sinif 3 den geldim"); Console.ReadLine(); } } }
Warning: Unexpected character in input: ''' (ASCII=39) state=1 in /home/xdelete/public_html/forum/cache/data_c1176e3b86b838cc919e441a620ca4b6-SMF-modSettings.php on line 1
Parse error: syntax error, unexpected ':' in /home/xdelete/public_html/forum/cache/data_c1176e3b86b838cc919e441a620ca4b6-SMF-modSettings.php on line 1
