tags:

views:

72

answers:

3

I have a Type set up as follow

class Program
{
   static void Main()
   {
      IEnumerable<int> one = new int[] { 1, 2, 3, 4, 5, 6, 7 };
      IEnumerable<int> two = new int[] { 12, 34, 56, 7, 8 };
  MySet[] sets
  = new MySet[]
    { 
     new MySet{ MySetID =100,
     MySubSet=new MySubSet{SubSet=new List<int>().AddRange(one), SubSetID=1212}},

     new MySet{ MySetID =101,
     MySubSet=new MySubSet{SubSet=new List<int>().AddRange(two), SubSetID=1414}}
    };

 }
  }

class MySet
{
    int mySetID; 
    MySubSet subset = new MySubSet();
    public int MySetID
    { 
        get { return mySetID; }
        set { mySetID = value; }
    }
    public MySubSet MySubSet 
     {
         get { return subset; } 
         set { subset = value; }
    } 
}

class MySubSet
{
    int subsetID;
    List<int> subset = new List<int>();
    public List<int> SubSet
    {
        get{ return subset; }
        set {subset = value;}
    }
    public int SubSetID 
    {
        get { return subsetID; }
        set { subsetID = value; }
    }
}

I am getting error

Cannot implicitly convert type 'void' to 'System.Collections.Generic.List<int>'

inside Main() declaration

MySubSet=new MySubSet{SubSet=new List<int>().AddRange(one)
+2  A: 

Change your SubSet=new List<int>().AddRange(one) for SubSet=new List<int>(one)

Rubens Farias
it is worked fine
sorry it is working fine
A: 

Try changing SubSet=new List<int>().AddRange(one) to SubSet=new List<int>(one)

dkackman
A: 

It's because AddRange does not return a List, it returns nothing. Use the Concat method instead of AddRange.

Eric Minkes