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


  •  private List<TCollection> _TCollection;

     this._TCollection[i] = es._TCollection[i].MyID;
    this gives the following error:

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

    how to dissolve this error!!
    please help.
    Monday, March 08, 2010 9:21 AM


All replies

  • What about explicit conversion?

     this._TCollection[i] = Convert.ToInt32(es._TCollection[i].MyID);
    Although I am not sure what type of List do you have in es. Mind sharing the declaration?
    Monday, March 08, 2010 9:30 AM
  • Mmm, what about:

    this._TCollection[i].MyID = es._TCollection[i].MyID;
    Monday, March 08, 2010 9:34 AM
  • es is a object of class having member variable  _TColection<>
    But the code is not working i have try this one out before

    Monday, March 08, 2010 9:35 AM
  • Try using System.Diagnostics.Debug.Print() to analyze the values of this._TCollection[i] and es._TCollection[i].MyID. Seems like MyID is a list of int, therefore try this:

     this._TCollection[i] = es._TCollection[i].MyID[0];

    You might want to replace the index on that.

    Monday, March 08, 2010 9:40 AM
  • _TCollection is a list of object  and MYID is a integer member variable.
    Monday, March 08, 2010 9:59 AM
  • You have a list of TCollection - which by itself is a list. So, basically you have a List of List (TCollection is a list of int). You should go the other way (my previous post applied):

    List<int> myCollection = this._TCollection[i];
    myCollection[i] = es._TCollection[i].MyID;

    Developing software using C#/C++. |
    Monday, March 08, 2010 10:04 AM
  • What is TCollection?
    Looks like it's a generic type parameter and it is constructed with List<int> where it should be constructed with int.

    Monday, March 08, 2010 10:06 AM
  • this._TCollection[i] is an array of int so you should do something like
    this._TCollection[i][j] = es._TCollection[i].MyID;

    My Blog - MSDN Complement by providing Visual C# Walkthroughs and Sample Codes - Founded In February 24, 2010
    Monday, March 08, 2010 10:08 AM
  • Are both this._TCollection and es._TCollection of the same type? If they are, shouldn't both have "MyID"?

    If you want to change the assignment to:  this._TCollection[i] = es._TCollection[i], try to implement copy constructors in TCollection.
    Monday, March 08, 2010 10:13 AM
  • Thanx very much
    Wednesday, March 10, 2010 7:29 AM