roger rickert

roger rickert

  • NA
  • 21
  • 1.1k

c#/winforms object array question

Jan 11 2021 5:28 PM
hello,
 
I'm still pretty new to C# and teaching myself. I've searched around and haven't found an answer, so I'm wondering if anyone can let me know if this is possible.
 
I need to have multiple instances of a class that can be accessed by multiple forms. I know I can do this with static class or a singleton. What I need to know is if it possible to have an array of these objects so that I can reference them by index.
 
something like this:
(pseudocode)
 
public class Thing {
public int var1;
public int var2;
}
 
then create using
 
Thing[ ] thing = new Thing[4];
 
and reference them like:
 
thing[0].var1 = something;
thing[0].var2 = something;
thing[1].var1 = something;
thing[1].var2 = something;
 
etc.
 
any info to point me in the right direction is appreciated. 

Answers (2)