c# code problem what does static mean

Discussion in 'Programming' started by neeshu, Apr 17, 2009.

  1. #1
    namespace functions
    {
        class Program
        {
           static int maxval(int[] maximum)
            {
                int bigvalue = maximum[0];
                for (int i = 0; i < maximum.Length; i++)
                {
                    if (bigvalue < maximum[i])
                    {
                        bigvalue = maximum[i];
                    }
                }
                return bigvalue;
            }
            static void Main(string[] args)
                {
                    int[] myarray = { 10, 10, 8, 20, 93, 78 };
                    int bigvalue = maxval(myarray);
                    Console.WriteLine("The largest value is "+ bigvalue);
                    Console.ReadKey();
                }
    
            }
           
        }
    HTML:
    When I remove the word static on line 5 before the function declaration and replace it with a acessor public or i just remove static completely I get an error

    an object reference is required for the non static field required something something

    what does static keyword do in C# why is it so important here do i need it in every function declaration
     
    neeshu, Apr 17, 2009 IP
  2. Sunny

    Sunny Well-Known Member

    Messages:
    734
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    130
    #2
    Sunny, Apr 17, 2009 IP
  3. neeshu

    neeshu Well-Known Member

    Messages:
    648
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    130
    #3
    thank u ji abhi dekhtey hai
     
    neeshu, Apr 18, 2009 IP