Hi there,
I very much like the sound of this ElementAtOrDefaultOperator for use with generic lists, but I cant figure out how to define a default type for my list of objects. From what I understand, the defaultvalue will be null if I have a list of objects as below, but I would like to return my own version of a default object with proper values. Here is what I mean:
ClassA {
string fieldA;
string fieldB;
ClassB fieldC;
//constructor
}
List<ClassA> myObjects = new List<ClassA>();
myObjects.Add( //new object )
myObjects.Add( //new object )
So I want to be able to do the following:
ClassA newObject = myObjects.ElementAtOrDefault(3);
And have newObject be a default type of ClassA that I define somewhere. I thought there might be a SetDefaultElement or some other method but I dont think it exists.
Any thoughts?