473,327 Members | 1,896 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 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 1420
<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: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.