Declaring and Using Global Arrays c#

前端 未结 8 2048
星月不相逢
星月不相逢 2020-12-30 12:02

I couldn\'t find any information pertaining to this question. I am trying to create a global array in C# so that I can input information into it at different points in my co

相关标签:
8条回答
  • 2020-12-30 12:35

    In C# there are no global variables. There are only class members. The best way to pass data from one part of your application to another is passing a reference to an object (an instance of a class) that holds all the relevant data in its members.

    You can also use static classes, which behave kind-of like global variables, but when you get more familiar with object-oriented programming you'll realize that this is not a good way to handle data.

    0 讨论(0)
  • 2020-12-30 12:35
    string[] values;
    

    Or to declare one of a particular length:

    string[] values = new string[6]; // creates an array with a length of 6.
    
    0 讨论(0)
提交回复
热议问题