0

I try to add multiple data type of data in one list.

public class DataList
{
    public List<int> DataOne=new List<int>();
    public int DataTwo;
    public double DataThree;
    public List<int> DataFour = new List<int>();

    public DataList(List<int> DataOne, int DataTwo, double DataThree, List<int> DataFour)
    {
      this.DataOne=DataOne;
      this.DataTwo=DataTwo; 
      this.DataThree=DataThree;
      this.DataFour=DataFour;
    }
}


public List<DataList> AddAllData = new List<final>();

AddAllData.Add(new DataList( ????? )); //<-Could add multiple data by one code?

thank you Guy solve this.


But for more: if

public class One
{
    public List<int> OneLise=new List<int>();
    public List<double> TwoLise=new List<int>();

    public One(List<int> OneLise, int TwoLise)
    {
      this.OneLise=OneLise;
      this.TwoLise=TwoLise; 

    }
}



public class DataList
{
    public List<One> DataOne=new List<One>();
    public int DataTwo;

    public DataList(List<One> DataOne, int DataTwo)
    {
      this.DataOne=DataOne;
      this.DataTwo=DataTwo; 

    }
}

AddAllData.Add(new DataList( ????? )); //<-Could add multiple data by one code?

e.g:something like that

AddAllData.Add(new DataList(DataOne.Add(5,2.3), 1, 5.3, DataFour.Add(4,2.65)));

I know one of method:

 public List<one> one = new List<one>();
 one.Add(5,2.3);
 public List<one> four = new List<one>();
 four.Add(4,2.65);
 AddAllData.Add(new DataList(one, 1, 5.3, four));

but it need more code to add data into list.

if AddAllData is more that 1000 element. it is waste time to add data

How to add multiple data type of data into one list by one code?

5
  • Does msdn.microsoft.com/en-us/library/… help? Commented Jun 18, 2017 at 12:03
  • you can try to use a dynamic object Commented Jun 18, 2017 at 12:06
  • Or this: stackoverflow.com/questions/12628222/… Commented Jun 18, 2017 at 12:10
  • Thank you. but AddRange is not helpful. when add first element in list "AddAllData", i need to add DataOne list and DataOne element to AddAllData at the same time Commented Jun 18, 2017 at 12:10
  • yes use ArrayList Commented Jun 18, 2017 at 12:29

1 Answer 1

0

You have to write the parameters to all the DataList manually or read them from file. But you can initialize AddAllData with DataList objects like this

// 3 DataLists example
List<DataList> AddAllData = new List<DataList>
{
    new DataList(new List<int> {5}, 1, 5.3, new List<int> {4}),
    new DataList(new List<int> {7}, 6, 4.3, new List<int> {9}),
    new DataList(new List<int> {3, 5}, 4, 5.3, new List<int> {4, 6, 7})
};
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. I try to follow this structure.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.