S
satyajit
Hi All,
I have a class that has a property returning IList. For example,
class A
{
public IList<string> MyList
{
get { return _list; }
set { _list = new List<string>(value); }
}
private List<string> _list;
}
Now, I have a method that has an IEnumerable and tries to set MyList
property of an object of type A. Here is how I have done it:
void f(A a, IEnumerable<string> list)
{
a.MyList = new List<string>(list);
}
The above works fine, but I think there must be a better way to
achieving this rather than create temporary List<string> objects. This
happens twice - 1) While converting from IEnumerable<> to IList<>, and
2) While converting from IList<> to List<> Last thing I would want is
to change the return type of the property or the signature of f(). Any
suggestions?
On side notes, how bad is it performance wise?
- Satyajit
I have a class that has a property returning IList. For example,
class A
{
public IList<string> MyList
{
get { return _list; }
set { _list = new List<string>(value); }
}
private List<string> _list;
}
Now, I have a method that has an IEnumerable and tries to set MyList
property of an object of type A. Here is how I have done it:
void f(A a, IEnumerable<string> list)
{
a.MyList = new List<string>(list);
}
The above works fine, but I think there must be a better way to
achieving this rather than create temporary List<string> objects. This
happens twice - 1) While converting from IEnumerable<> to IList<>, and
2) While converting from IList<> to List<> Last thing I would want is
to change the return type of the property or the signature of f(). Any
suggestions?
On side notes, how bad is it performance wise?
- Satyajit