Storing different types inside a list?

后端 未结 6 1018
广开言路
广开言路 2021-02-19 03:34

Related: A list of multiple data types?

I want to know how to store different array types (including system types) inside an array.

The above question covered ho

6条回答
  •  鱼传尺愫
    2021-02-19 03:41

    You should create a class

    public class MyClass
    {
        public string x {get;set;}
        public double y{get;set;}
    }
    

    Then just create an array of that class. This class can have whatever types you want, that's the beauty of having objects in an object oriented language.

    public MyClass[] someList=new MyClass[insert_number_of_elements];
    

提交回复
热议问题