Okay, I tried to research this, I tried to read Bechir's article about generic collection types, http://www.c-sharpcorner.com/UploadFile/yougerthen/105032008145435PM/1.aspx but I think it is beyond my current skill level with C#.
I have a class called StepClass and I want to reference it in another class as an array (or collection?). I can define all the methods for StepClass for "count" and "add" etc, but a friend at work mentioned that I should use System.Collections.Generic to do this, but the examples I've seen are a little confusing. Would someone be able to give a simple prototype how I would do that?
so instead of
private StepClass[] Steps;
what would I use? I was hoping there would be something that would allow me to reference my own methods within StepClass with Steps[i].method or similar. Hope I'm explaining this ok.
Bechir BejaouiPosted Dec 9, 2008, 7:10 PM
So read this one as you will see it is not necessary to always use generics
http://www.c-sharpcorner.com/UploadFile/yougerthen/104262008165723PM/1.aspx
I think it fairily fit your needs. Else feel free to send me back
Bechir BejaouiPosted Dec 11, 2008, 6:24 PM
I give you a real use case of IEnumrable interface, this interface should be implented, I mean your class should implement it if you plan to create a customised container other that array list<> ArrayList Dictionary HashTable and so forth. Because the IEnumerable Interface has a method GetEnumerator this last one returns an IEnumerator object that enables you enumerate objects within a given collection
for example if you try to use a foreach to enumerate the collection within a customized container you will recive and error that indicates your container doesn't implement the IEnumerable because the IEnumerator that render that possible is missing
Jeff JohnsonPosted Dec 11, 2008, 8:31 AM
Bechir BejaouiPosted Dec 11, 2008, 5:49 AM
Jeff JohnsonPosted Dec 10, 2008, 11:32 PM
Okay..... question. My class is void since it doesn't need to return anything I'm getting the error below which is tied to the
return this.StepList.GetEnumerator();
Error 1 Since 'Predicate2.Job.Job(Predicate2.LogonInfo, string, string)' returns void, a return keyword must not be followed by an object expression.
Any suggestions how to handle this? Thanks.
Bechir BejaouiPosted Dec 10, 2008, 7:07 PM
Jeff JohnsonPosted Dec 10, 2008, 3:37 PM
lol, ok, will do. Thanks again.
Jeff
Bechir BejaouiPosted Dec 10, 2008, 3:28 PM
Then you can use a generic list to stock your objects,
generics have two benefits avoid error convesation especially when boxing(convert from type to object) and unboxing(convert from object to type) objects becasue generaly errors do not appear at the compile time in that case
second it increases dramatically the performance when type conversions are needed within a loop block. If you have any question about generics don't hesitate to ask me
Jeff JohnsonPosted Dec 10, 2008, 8:46 AM
Thanks Bechir, that one is definitely more my speed for now. The generics does look neat. Once my comfort factor eases to this enumerator I may take on the generics article with more gusto. I just started playing with C# 5 days ago. I have a C and C++ history 12 years ago and am just getting into the swing of things.
Thanks again.
Jeff