frenchie
frenchie

Reputation: 52047

writing a foreach statement to loop within a collection

I have a function defined like this:

public static bool ComposeObjects(List<ObjectID> TheListOfIDs)

The definition of ObjectID looks like this:

public class ObjectID
{
    int ObjectID { get; set; }
    byte Var1 { get; set; }
}

This function ComposeObjects receives a collection of ObjectIDs and I want to loop in this collection.

How do you write the for each statement?

So far I have

foreach (ObjectID in TheListOfIDs)
{
    // ...
}

Thanks for your suggestion.

Upvotes: 0

Views: 109

Answers (2)

asawyer
asawyer

Reputation: 17808

Your having a syntax problem? What errors? What have you tried?

foreach (var oID in TheListOfIDs)
{
...
}

Upvotes: 0

Jon Skeet
Jon Skeet

Reputation: 1503589

You need to give a variable name:

foreach (ObjectID id in TheListOfIDs)
{
   // Just for example...
   int x = id.ObjectID;
   byte b = id.Var1;
}

Upvotes: 9

Related Questions