Logo Background

Static değişkenler (Global Değişkenler)

  • Written by ElektronikElektronik İlk Yorumu Sen Yaz. Comments
    Last Updated: Şubat 20, 2009

    Sınıflarda static methodlar olduğu gibi static alanlarda olabilir. Diğer dillerinde global değişken olarak adlandırılan değişkenleri csharpta public static olarak tanımlayıp sınıfadi.değişkenadi şeklinde heryerden çağırabiliriz.
    Aşağıda csharpta yazılmış ufak bir örneğimiz bulunmaktadır.

    ?View Code CSHARP
    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
    
    using System;
    using System.Collections.Generic;
    using System.Text;
     
    namespace siniflarrr
    {
        class AnaSinif
        {
            class degiskenler
            {
                //degişkeni static olarak belirtiyoruz.
                public static int deger = 10;
            }
            class Aritmetik
            {
                public static int Toplama(int x, int y)
                {
                    return x + y;
                }
            }
     
            public static void Main(string[] args)
            {
                int sonuc;
                sonuc = Aritmetik.Toplama(100, 200);
               //Değişkeni sınıfadi.degisken seklinde çağırıyoruz.
                // Sonuc ile değişkeni toplayıp sonuca yazdırıyoruz.
                sonuc += degiskenler.deger;
                Console.WriteLine(sonuc);
                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