VB.NET LINQ Query: Getting The Sum of All Values For A Specific Structure Member

后端 未结 2 1310
长情又很酷
长情又很酷 2021-02-18 16:53

In VB.NET, let\'s assume I have the following Structure:

Public Structure Product
    Public ItemNo As Int32
    Public Description As String
    Public Cost As          


        
2条回答
  •  轮回少年
    2021-02-18 17:26

    The built in Sum method does this already.

    In VB it looks like this:

    ProductList.Sum(Function(item) item.Cost)
    

    In C# it looks like this:

    ProductsList.Sum( (item) => item.Cost);
    

提交回复
热议问题