472,975 Members | 1,304 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,975 software developers and data experts.

Lists<> of custom classes

Hi,

I've made my own class (we'll call it myClass) to simply store some
data. I'm storing multiple instances myClass in a list:

List<myClass> myList = new List<myClass>();
myList.Add(new myClass(somedata));
myList.Add(new myClass(somemoredata));

I'm then iterating over myList using a for loop. To neaten my code i
decided to use a foreach, but of course, when i do that i get some
serialization error because myClass doesnt implement GetEnumerator.

I've read this:
http://www.vijaymukhi.com/documents/...ics/chap13.htm

but I'm still not very clear on how I need to modify myClass to enable
foreach-ing.

Can someone please advise me?

Thanks,

Andrew

Below is the code for myClass:
////////////

internal class myClass
{
public int X;
public int Y;

public myClass(int _x, int _y)
{
X = _x;
Y = _y;
}
}
}
Feb 18 '06 #1
4 1405
<snip>

Hmmmm... seems to be working now, and I haven't changed anything :s

Sorry
Andrew
Feb 18 '06 #2
Don't you just hate that!

I'd better offer you a job before anyone else does.

I'm always on the look out for someone who can correct problems in code
without changing anything.

It's a talent that most of us don't have.

Rather than 'I haven't changed anything', I'll wager that it is more a
matter of 'I don't know what I changed' or 'I don't know what I did
differently'.
"Andrew Bullock" <an*********************@ANDntlworldTHIS.com> wrote in
message news:MS*******************@newsfe4-win.ntli.net...
<snip>

Hmmmm... seems to be working now, and I haven't changed anything :s

Sorry
Andrew

Feb 18 '06 #3
Stephany Young wrote:
Don't you just hate that!

I'd better offer you a job before anyone else does.

I'm always on the look out for someone who can correct problems in code
without changing anything.

It's a talent that most of us don't have.

Rather than 'I haven't changed anything', I'll wager that it is more a
matter of 'I don't know what I changed' or 'I don't know what I did
differently'.


Nope, honestly I didn't change a thing!

I think its something to do with the debugger and breakpoints...

/investigates

Andrew
Feb 18 '06 #4
SP

"Andrew Bullock" <an*********************@ANDntlworldTHIS.com> wrote in
message news:WA*******************@newsfe6-win.ntli.net...
Hi,

I've made my own class (we'll call it myClass) to simply store some data.
I'm storing multiple instances myClass in a list:

List<myClass> myList = new List<myClass>();
myList.Add(new myClass(somedata));
myList.Add(new myClass(somemoredata));

I'm then iterating over myList using a for loop. To neaten my code i
decided to use a foreach, but of course, when i do that i get some
serialization error because myClass doesnt implement GetEnumerator.


It doesn't have to. The foreach is performed on the List<> not your class.

SP
Feb 19 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

44
by: seberino | last post by:
Tuples are defined with regards to parentheses ()'s as everyone knows. This causes confusion for 1 item tuples since (5) can be interpreted as a tuple OR as the number 5 in a mathematical...
7
by: Dave | last post by:
Hello all, I'm pondering why the default underlying container for std::priority_queue<> is std::vector<>. It would seem that inserts are liable to happen anywhere, which would make std::list<>...
4
by: Peter Notebaert | last post by:
I am new to Python and have to create an import library in C that uses matrices. These matrices can be one-dimensional (vectors) or two-dimensional. If I look in the ActivePython 2.4...
4
by: Emre Guldogan | last post by:
Is there any resource that lists the functions of asp which are available in C#.NET or lists the equivalence of these functions in C#.NET. thanks...
2
by: Robert Bravery | last post by:
Hi all I create a generic list like this: private List<string_DimensionList = new List<string>(); How can I create a list having two columns of type int and string Then I normally add to the...
1
by: Eran | last post by:
Hi, I have a huge data structure, which I previosly stored in a Dictionary<int, MyObj> MyObj is relatively small (2 int, 1 DateTime, 1 bool). The dictionary I am using is quite large...
20
by: martin-g | last post by:
Hi. Mostly I program in C++, and I'm not fluent in C# and .NET. In my last project I began to use LinkedList<and suddenly noticed that can't find a way to sort it. Does it mean I must implement...
45
by: Zytan | last post by:
This returns the following error: "Cannot modify the return value of 'System.Collections.Generic.List<MyStruct>.this' because it is not a variable" and I have no idea why! Do lists return copies...
3
by: muquaddim | last post by:
Hello, I have a xml file like the following. <?xml version="1.0"> <data> <idef units="Vin,Vout,E"> <i id="i1"> <sample num="1"> <sampledata value="2;3;7" /> </sample>
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.