开发者

writing a foreach statement to loop within a collection

开发者 https://www.devze.com 2023-02-22 01:23 出处:网络
I have a fun开发者_StackOverflowction defined like this: public static bool ComposeObjects(List<ObjectID> TheListOfIDs)

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

精彩评论

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