T
Tony Johansson
Hello!
I'm reading in a book and here is a property that doesn't make sense at all.
the code look like this.
public List<FoodItem> FoodList
{
get
{
FoodItem[] listCopy = null;
listCopy = new FoodItem[]{};
m_foodItemList.CopyTo(listCopy);
return m_foodItemList;
}
set
{
m_foodItemList = value;
}
}
This code create a local copy in an array named listCopy from the original
collection m_foodItemList.
The code then return the original collection m_foodItemList.
So what is the point to create a local array that will go out of scope when
the original collection m_foodItemList is returned.
//Tony
I'm reading in a book and here is a property that doesn't make sense at all.
the code look like this.
public List<FoodItem> FoodList
{
get
{
FoodItem[] listCopy = null;
listCopy = new FoodItem[]{};
m_foodItemList.CopyTo(listCopy);
return m_foodItemList;
}
set
{
m_foodItemList = value;
}
}
This code create a local copy in an array named listCopy from the original
collection m_foodItemList.
The code then return the original collection m_foodItemList.
So what is the point to create a local array that will go out of scope when
the original collection m_foodItemList is returned.
//Tony