开发者

How can i access anonymous types without FOREACHLOOP?

How can i get test all data . i want to access test.stockdescid a开发者_如何学JAVAnd test.barcode

please don't post :

foreach (var person in  myQuery)

    {

        Console.WriteLine(person);

    }

 var test =  (from s in stock.StockMaterials
                                              where (s.date<= DateTime.Now &&
                                              s.date.ToString() != "01/01/1900 00:00") &&
                                              s.id == ItemID &&
                                              s.chkdate == true
                                              select new { stockdescid= s.stockdescid,barcode=s.barcode});
                        if (ID.First() == ItemID)
                            ReturnMsg = "E1: Please check the expiry date : "+test.First().barcode.ToString();


Anonymous types can be accessed only from the method where they are created.

You say

"i want to access test.stockdescid and test.barcode"

But "test" is a collection, and the properties you want to access are on the items of the collection, not on the collection itself.

You don't have a test.barcode but rather test.First().barcode and so on.

That said, I don't clearly understand what you need to do. Can you try to be more clear about your goal?


What do you mean "get test all data"?

You can write...

test.ToList().ForEach(i => i.DoSomething());

if that helps?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜