开发者

writing a foreach statement to loop within a collection

I have a fun开发者_StackOverflowction 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.


You need to give a variable name:

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


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

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜