VB :: Code & APIs

[VB.NET] LINQ 를 이용하여 평균 구하는 방법

[VB.NET] LINQ 를 이용하여 평균 구하는 방법.

Dim avg = dt.AsEnumerable().[Select](Function(x) New With {
       Key .Carrier = x.Field(Of String)("Carrier"),
       Key .Name = x.Field(Of String)("Name"),
       Key .Avg = x.Field(Of Int32)("Level")
   }).Where(Function(s) s.Carrier = "X" AndAlso s.Name = "X")
                                            .[Select](Function(h) h.Avg).FirstOrDefault()

If row.Count > 0 Then
    avgValueTC = row.AsEnumerable().Average(Function(x) x.Field(Of String)("Column 1"))
    avgValueRD = row.AsEnumerable().Average(Function(x) x.Field(Of String)("Column 2"))
    avgValueTC = CDbl(0.0)
    avgValueRD = CDbl(0.0)
End If

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: