Enumerable.Sum Enumerable.Sum Enumerable.Sum Enumerable.Sum Method

정의

숫자 값 시퀀스의 합을 계산합니다.Computes the sum of a sequence of numeric values.

오버로드

Sum(IEnumerable<Nullable<Int32>>) Sum(IEnumerable<Nullable<Int32>>) Sum(IEnumerable<Nullable<Int32>>) Sum(IEnumerable<Nullable<Int32>>)

nullable Int32 값 시퀀스의 합을 계산합니다.Computes the sum of a sequence of nullable Int32 values.

Sum(IEnumerable<Nullable<Single>>) Sum(IEnumerable<Nullable<Single>>) Sum(IEnumerable<Nullable<Single>>) Sum(IEnumerable<Nullable<Single>>)

nullable Single 값 시퀀스의 합을 계산합니다.Computes the sum of a sequence of nullable Single values.

Sum(IEnumerable<Single>) Sum(IEnumerable<Single>) Sum(IEnumerable<Single>) Sum(IEnumerable<Single>)

Single 값 시퀀스의 합을 계산합니다.Computes the sum of a sequence of Single values.

Sum(IEnumerable<Nullable<Int64>>) Sum(IEnumerable<Nullable<Int64>>) Sum(IEnumerable<Nullable<Int64>>) Sum(IEnumerable<Nullable<Int64>>)

nullable Int64 값 시퀀스의 합을 계산합니다.Computes the sum of a sequence of nullable Int64 values.

Sum(IEnumerable<Nullable<Double>>) Sum(IEnumerable<Nullable<Double>>) Sum(IEnumerable<Nullable<Double>>) Sum(IEnumerable<Nullable<Double>>)

nullable Double 값 시퀀스의 합을 계산합니다.Computes the sum of a sequence of nullable Double values.

Sum(IEnumerable<Double>) Sum(IEnumerable<Double>) Sum(IEnumerable<Double>) Sum(IEnumerable<Double>)

Double 값 시퀀스의 합을 계산합니다.Computes the sum of a sequence of Double values.

Sum(IEnumerable<Int64>) Sum(IEnumerable<Int64>) Sum(IEnumerable<Int64>) Sum(IEnumerable<Int64>)

Int64 값 시퀀스의 합을 계산합니다.Computes the sum of a sequence of Int64 values.

Sum(IEnumerable<Int32>) Sum(IEnumerable<Int32>) Sum(IEnumerable<Int32>) Sum(IEnumerable<Int32>)

Int32 값 시퀀스의 합을 계산합니다.Computes the sum of a sequence of Int32 values.

Sum(IEnumerable<Decimal>) Sum(IEnumerable<Decimal>) Sum(IEnumerable<Decimal>) Sum(IEnumerable<Decimal>)

Decimal 값 시퀀스의 합을 계산합니다.Computes the sum of a sequence of Decimal values.

Sum(IEnumerable<Nullable<Decimal>>) Sum(IEnumerable<Nullable<Decimal>>) Sum(IEnumerable<Nullable<Decimal>>) Sum(IEnumerable<Nullable<Decimal>>)

nullable Decimal 값 시퀀스의 합을 계산합니다.Computes the sum of a sequence of nullable Decimal values.

Sum<TSource>(IEnumerable<TSource>, Func<TSource,Single>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Single>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Single>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Single>)

입력 시퀀스의 각 요소에 대해 변형 함수를 호출하여 가져온 Single 값 시퀀스의 합을 계산합니다.Computes the sum of the sequence of Single values that are obtained by invoking a transform function on each element of the input sequence.

Sum<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Single>>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Single>>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Single>>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Single>>)

입력 시퀀스의 각 요소에 대해 변형 함수를 호출하여 가져온 nullable Single 값 시퀀스의 합을 계산합니다.Computes the sum of the sequence of nullable Single values that are obtained by invoking a transform function on each element of the input sequence.

Sum<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Int64>>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Int64>>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Int64>>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Int64>>)

입력 시퀀스의 각 요소에 대해 변형 함수를 호출하여 가져온 nullable Int64 값 시퀀스의 합을 계산합니다.Computes the sum of the sequence of nullable Int64 values that are obtained by invoking a transform function on each element of the input sequence.

Sum<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Int32>>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Int32>>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Int32>>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Int32>>)

입력 시퀀스의 각 요소에 대해 변형 함수를 호출하여 가져온 nullable Int32 값 시퀀스의 합을 계산합니다.Computes the sum of the sequence of nullable Int32 values that are obtained by invoking a transform function on each element of the input sequence.

Sum<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Double>>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Double>>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Double>>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Double>>)

입력 시퀀스의 각 요소에 대해 변형 함수를 호출하여 가져온 nullable Double 값 시퀀스의 합을 계산합니다.Computes the sum of the sequence of nullable Double values that are obtained by invoking a transform function on each element of the input sequence.

Sum<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Decimal>>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Decimal>>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Decimal>>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Decimal>>)

입력 시퀀스의 각 요소에 대해 변형 함수를 호출하여 가져온 nullable Decimal 값 시퀀스의 합을 계산합니다.Computes the sum of the sequence of nullable Decimal values that are obtained by invoking a transform function on each element of the input sequence.

Sum<TSource>(IEnumerable<TSource>, Func<TSource,Int64>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Int64>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Int64>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Int64>)

입력 시퀀스의 각 요소에 대해 변형 함수를 호출하여 가져온 Int64 값 시퀀스의 합을 계산합니다.Computes the sum of the sequence of Int64 values that are obtained by invoking a transform function on each element of the input sequence.

Sum<TSource>(IEnumerable<TSource>, Func<TSource,Int32>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Int32>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Int32>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Int32>)

입력 시퀀스의 각 요소에 대해 변형 함수를 호출하여 가져온 Int32 값 시퀀스의 합을 계산합니다.Computes the sum of the sequence of Int32 values that are obtained by invoking a transform function on each element of the input sequence.

Sum<TSource>(IEnumerable<TSource>, Func<TSource,Double>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Double>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Double>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Double>)

입력 시퀀스의 각 요소에 대해 변형 함수를 호출하여 가져온 Double 값 시퀀스의 합을 계산합니다.Computes the sum of the sequence of Double values that are obtained by invoking a transform function on each element of the input sequence.

Sum<TSource>(IEnumerable<TSource>, Func<TSource,Decimal>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Decimal>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Decimal>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Decimal>)

입력 시퀀스의 각 요소에 대해 변형 함수를 호출하여 가져온 Decimal 값 시퀀스의 합을 계산합니다.Computes the sum of the sequence of Decimal values that are obtained by invoking a transform function on each element of the input sequence.

Sum(IEnumerable<Nullable<Int32>>) Sum(IEnumerable<Nullable<Int32>>) Sum(IEnumerable<Nullable<Int32>>) Sum(IEnumerable<Nullable<Int32>>)

nullable Int32 값 시퀀스의 합을 계산합니다.Computes the sum of a sequence of nullable Int32 values.

public:
[System::Runtime::CompilerServices::Extension]
 static Nullable<int> Sum(System::Collections::Generic::IEnumerable<Nullable<int>> ^ source);
public static Nullable<int> Sum (this System.Collections.Generic.IEnumerable<Nullable<int>> source);
static member Sum : seq<Nullable<int>> -> Nullable<int>
<Extension()>
Public Function Sum (source As IEnumerable(Of Nullable(Of Integer))) As Nullable(Of Integer)

매개 변수

source
IEnumerable<Nullable<Int32>>

합을 계산할 nullable Int32 값의 시퀀스입니다.A sequence of nullable Int32 values to calculate the sum of.

반환

시퀀스에 있는 값의 합입니다.The sum of the values in the sequence.

예외

합계가 MaxValue보다 큰 경우The sum is larger than MaxValue.

예제

다음 코드 예제에 사용 하는 방법을 보여 줍니다. Sum(IEnumerable<Nullable<Single>>) 값 시퀀스의 합계입니다.The following code example demonstrates how to use Sum(IEnumerable<Nullable<Single>>) to sum the values of a sequence.

참고

이 코드 예제에서는 이 항목에서 설명하는 특정 오버로드와는 다른 이 오버로드된 메서드의 오버로드를 사용합니다.This code example uses an overload of this overloaded method that is different from the specific overload that this topic describes. 이 항목의 예제를 확장하려면 소스 시퀀스의 요소를 적절한 숫자 형식의 요소로 대체하십시오.To extend the example to this topic, substitute the elements of the source sequence with elements of the appropriate numerical type.

float?[] points = { null, 0, 92.83F, null, 100.0F, 37.46F, 81.1F };

float? sum = points.Sum();

Console.WriteLine("Total points earned: {0}", sum);

/*
 This code produces the following output:

 Total points earned: 311.39
*/
' Create an array of Nullable Single values.
Dim points() As Nullable(Of Single) =
{Nothing, 0, 92.83F, Nothing, 100.0F, 37.46F, 81.1F}

' Get the sum of values in the list.
Dim sum As Nullable(Of Single) = points.Sum()

' Display the output.
MsgBox("Total points earned: " & sum)

' This code produces the following output:
'
' Total points earned: 311.39

설명

이 메서드는 경우 0을 반환 source 요소가 없는.This method returns zero if source contains no elements.

결과 값을 포함 하지 않습니다 null합니다.The result does not include values that are null.

Visual Basic 쿼리 식 구문에는 Aggregate Into Sum() 절 뒤에 변환 Sum합니다.In Visual Basic query expression syntax, an Aggregate Into Sum() clause translates to an invocation of Sum.

추가 정보

Sum(IEnumerable<Nullable<Single>>) Sum(IEnumerable<Nullable<Single>>) Sum(IEnumerable<Nullable<Single>>) Sum(IEnumerable<Nullable<Single>>)

nullable Single 값 시퀀스의 합을 계산합니다.Computes the sum of a sequence of nullable Single values.

public:
[System::Runtime::CompilerServices::Extension]
 static Nullable<float> Sum(System::Collections::Generic::IEnumerable<Nullable<float>> ^ source);
public static Nullable<float> Sum (this System.Collections.Generic.IEnumerable<Nullable<float>> source);
static member Sum : seq<Nullable<single>> -> Nullable<single>
<Extension()>
Public Function Sum (source As IEnumerable(Of Nullable(Of Single))) As Nullable(Of Single)

매개 변수

source
IEnumerable<Nullable<Single>>

합을 계산할 nullable Single 값의 시퀀스입니다.A sequence of nullable Single values to calculate the sum of.

반환

시퀀스에 있는 값의 합입니다.The sum of the values in the sequence.

예외

예제

다음 코드 예제에 사용 하는 방법을 보여 줍니다. Sum(IEnumerable<Nullable<Single>>) 값 시퀀스의 합계입니다.The following code example demonstrates how to use Sum(IEnumerable<Nullable<Single>>) to sum the values of a sequence.

float?[] points = { null, 0, 92.83F, null, 100.0F, 37.46F, 81.1F };

float? sum = points.Sum();

Console.WriteLine("Total points earned: {0}", sum);

/*
 This code produces the following output:

 Total points earned: 311.39
*/
' Create an array of Nullable Single values.
Dim points() As Nullable(Of Single) =
{Nothing, 0, 92.83F, Nothing, 100.0F, 37.46F, 81.1F}

' Get the sum of values in the list.
Dim sum As Nullable(Of Single) = points.Sum()

' Display the output.
MsgBox("Total points earned: " & sum)

' This code produces the following output:
'
' Total points earned: 311.39

설명

이 메서드는 경우 0을 반환 source 요소가 없는.This method returns zero if source contains no elements.

결과 값을 포함 하지 않습니다 null합니다.The result does not include values that are null.

Visual Basic 쿼리 식 구문에는 Aggregate Into Sum() 절 뒤에 변환 Sum합니다.In Visual Basic query expression syntax, an Aggregate Into Sum() clause translates to an invocation of Sum.

추가 정보

Sum(IEnumerable<Single>) Sum(IEnumerable<Single>) Sum(IEnumerable<Single>) Sum(IEnumerable<Single>)

Single 값 시퀀스의 합을 계산합니다.Computes the sum of a sequence of Single values.

public:
[System::Runtime::CompilerServices::Extension]
 static float Sum(System::Collections::Generic::IEnumerable<float> ^ source);
public static float Sum (this System.Collections.Generic.IEnumerable<float> source);
static member Sum : seq<single> -> single
<Extension()>
Public Function Sum (source As IEnumerable(Of Single)) As Single

매개 변수

source
IEnumerable<Single>

합을 계산할 Single 값의 시퀀스입니다.A sequence of Single values to calculate the sum of.

반환

시퀀스에 있는 값의 합입니다.The sum of the values in the sequence.

예외

예제

다음 코드 예제에 사용 하는 방법을 보여 줍니다. Sum(IEnumerable<Single>) 값 시퀀스의 합계입니다.The following code example demonstrates how to use Sum(IEnumerable<Single>) to sum the values of a sequence.

List<float> numbers = new List<float> { 43.68F, 1.25F, 583.7F, 6.5F };

float sum = numbers.Sum();

Console.WriteLine("The sum of the numbers is {0}.", sum);

/*
 This code produces the following output:

 The sum of the numbers is 635.13.
*/
' Create a list of Single values.
Dim numbers As New List(Of Single)(New Single() _
                               {43.68F, 1.25F, 583.7F, 6.5F})

' Get the sum of values in the list.
Dim sum As Single = numbers.Sum()

' Display the output.
MsgBox("The sum of the numbers is " & sum)

' This code produces the following output:
'
' The sum of the numbers is 635.13

설명

이 메서드는 경우 0을 반환 source 요소가 없는.This method returns zero if source contains no elements.

Visual Basic 쿼리 식 구문에는 Aggregate Into Sum() 절 뒤에 변환 Sum합니다.In Visual Basic query expression syntax, an Aggregate Into Sum() clause translates to an invocation of Sum.

추가 정보

Sum(IEnumerable<Nullable<Int64>>) Sum(IEnumerable<Nullable<Int64>>) Sum(IEnumerable<Nullable<Int64>>) Sum(IEnumerable<Nullable<Int64>>)

nullable Int64 값 시퀀스의 합을 계산합니다.Computes the sum of a sequence of nullable Int64 values.

public:
[System::Runtime::CompilerServices::Extension]
 static Nullable<long> Sum(System::Collections::Generic::IEnumerable<Nullable<long>> ^ source);
public static Nullable<long> Sum (this System.Collections.Generic.IEnumerable<Nullable<long>> source);
static member Sum : seq<Nullable<int64>> -> Nullable<int64>
<Extension()>
Public Function Sum (source As IEnumerable(Of Nullable(Of Long))) As Nullable(Of Long)

매개 변수

source
IEnumerable<Nullable<Int64>>

합을 계산할 nullable Int64 값의 시퀀스입니다.A sequence of nullable Int64 values to calculate the sum of.

반환

시퀀스에 있는 값의 합입니다.The sum of the values in the sequence.

예외

합계가 MaxValue보다 큰 경우The sum is larger than MaxValue.

예제

다음 코드 예제에 사용 하는 방법을 보여 줍니다. Sum(IEnumerable<Nullable<Single>>) 값 시퀀스의 합계입니다.The following code example demonstrates how to use Sum(IEnumerable<Nullable<Single>>) to sum the values of a sequence.

참고

이 코드 예제에서는 이 항목에서 설명하는 특정 오버로드와는 다른 이 오버로드된 메서드의 오버로드를 사용합니다.This code example uses an overload of this overloaded method that is different from the specific overload that this topic describes. 이 항목의 예제를 확장하려면 소스 시퀀스의 요소를 적절한 숫자 형식의 요소로 대체하십시오.To extend the example to this topic, substitute the elements of the source sequence with elements of the appropriate numerical type.

float?[] points = { null, 0, 92.83F, null, 100.0F, 37.46F, 81.1F };

float? sum = points.Sum();

Console.WriteLine("Total points earned: {0}", sum);

/*
 This code produces the following output:

 Total points earned: 311.39
*/
' Create an array of Nullable Single values.
Dim points() As Nullable(Of Single) =
{Nothing, 0, 92.83F, Nothing, 100.0F, 37.46F, 81.1F}

' Get the sum of values in the list.
Dim sum As Nullable(Of Single) = points.Sum()

' Display the output.
MsgBox("Total points earned: " & sum)

' This code produces the following output:
'
' Total points earned: 311.39

설명

이 메서드는 경우 0을 반환 source 요소가 없는.This method returns zero if source contains no elements.

결과 값을 포함 하지 않습니다 null합니다.The result does not include values that are null.

Visual Basic 쿼리 식 구문에는 Aggregate Into Sum() 절 뒤에 변환 Sum합니다.In Visual Basic query expression syntax, an Aggregate Into Sum() clause translates to an invocation of Sum.

추가 정보

Sum(IEnumerable<Nullable<Double>>) Sum(IEnumerable<Nullable<Double>>) Sum(IEnumerable<Nullable<Double>>) Sum(IEnumerable<Nullable<Double>>)

nullable Double 값 시퀀스의 합을 계산합니다.Computes the sum of a sequence of nullable Double values.

public:
[System::Runtime::CompilerServices::Extension]
 static Nullable<double> Sum(System::Collections::Generic::IEnumerable<Nullable<double>> ^ source);
public static Nullable<double> Sum (this System.Collections.Generic.IEnumerable<Nullable<double>> source);
static member Sum : seq<Nullable<double>> -> Nullable<double>
<Extension()>
Public Function Sum (source As IEnumerable(Of Nullable(Of Double))) As Nullable(Of Double)

매개 변수

source
IEnumerable<Nullable<Double>>

합을 계산할 nullable Double 값의 시퀀스입니다.A sequence of nullable Double values to calculate the sum of.

반환

시퀀스에 있는 값의 합입니다.The sum of the values in the sequence.

예외

예제

다음 코드 예제에 사용 하는 방법을 보여 줍니다. Sum(IEnumerable<Nullable<Single>>) 값 시퀀스의 합계입니다.The following code example demonstrates how to use Sum(IEnumerable<Nullable<Single>>) to sum the values of a sequence.

참고

이 코드 예제에서는 이 항목에서 설명하는 특정 오버로드와는 다른 이 오버로드된 메서드의 오버로드를 사용합니다.This code example uses an overload of this overloaded method that is different from the specific overload that this topic describes. 이 항목의 예제를 확장하려면 소스 시퀀스의 요소를 적절한 숫자 형식의 요소로 대체하십시오.To extend the example to this topic, substitute the elements of the source sequence with elements of the appropriate numerical type.

float?[] points = { null, 0, 92.83F, null, 100.0F, 37.46F, 81.1F };

float? sum = points.Sum();

Console.WriteLine("Total points earned: {0}", sum);

/*
 This code produces the following output:

 Total points earned: 311.39
*/
' Create an array of Nullable Single values.
Dim points() As Nullable(Of Single) =
{Nothing, 0, 92.83F, Nothing, 100.0F, 37.46F, 81.1F}

' Get the sum of values in the list.
Dim sum As Nullable(Of Single) = points.Sum()

' Display the output.
MsgBox("Total points earned: " & sum)

' This code produces the following output:
'
' Total points earned: 311.39

설명

이 메서드는 경우 0을 반환 source 요소가 없는.This method returns zero if source contains no elements.

결과 값을 포함 하지 않습니다 null합니다.The result does not include values that are null.

Visual Basic 쿼리 식 구문에는 Aggregate Into Sum() 절 뒤에 변환 Sum합니다.In Visual Basic query expression syntax, an Aggregate Into Sum() clause translates to an invocation of Sum.

추가 정보

Sum(IEnumerable<Double>) Sum(IEnumerable<Double>) Sum(IEnumerable<Double>) Sum(IEnumerable<Double>)

Double 값 시퀀스의 합을 계산합니다.Computes the sum of a sequence of Double values.

public:
[System::Runtime::CompilerServices::Extension]
 static double Sum(System::Collections::Generic::IEnumerable<double> ^ source);
public static double Sum (this System.Collections.Generic.IEnumerable<double> source);
static member Sum : seq<double> -> double
<Extension()>
Public Function Sum (source As IEnumerable(Of Double)) As Double

매개 변수

source
IEnumerable<Double>

합을 계산할 Double 값의 시퀀스입니다.A sequence of Double values to calculate the sum of.

반환

시퀀스에 있는 값의 합입니다.The sum of the values in the sequence.

예외

예제

다음 코드 예제에 사용 하는 방법을 보여 줍니다. Sum(IEnumerable<Single>) 값 시퀀스의 합계입니다.The following code example demonstrates how to use Sum(IEnumerable<Single>) to sum the values of a sequence.

참고

이 코드 예제에서는 이 항목에서 설명하는 특정 오버로드와는 다른 이 오버로드된 메서드의 오버로드를 사용합니다.This code example uses an overload of this overloaded method that is different from the specific overload that this topic describes. 이 항목의 예제를 확장하려면 소스 시퀀스의 요소를 적절한 숫자 형식의 요소로 대체하십시오.To extend the example to this topic, substitute the elements of the source sequence with elements of the appropriate numerical type.

List<float> numbers = new List<float> { 43.68F, 1.25F, 583.7F, 6.5F };

float sum = numbers.Sum();

Console.WriteLine("The sum of the numbers is {0}.", sum);

/*
 This code produces the following output:

 The sum of the numbers is 635.13.
*/
' Create a list of Single values.
Dim numbers As New List(Of Single)(New Single() _
                               {43.68F, 1.25F, 583.7F, 6.5F})

' Get the sum of values in the list.
Dim sum As Single = numbers.Sum()

' Display the output.
MsgBox("The sum of the numbers is " & sum)

' This code produces the following output:
'
' The sum of the numbers is 635.13

설명

이 메서드는 경우 0을 반환 source 요소가 없는.This method returns zero if source contains no elements.

Visual Basic 쿼리 식 구문에는 Aggregate Into Sum() 절 뒤에 변환 Sum합니다.In Visual Basic query expression syntax, an Aggregate Into Sum() clause translates to an invocation of Sum.

추가 정보

Sum(IEnumerable<Int64>) Sum(IEnumerable<Int64>) Sum(IEnumerable<Int64>) Sum(IEnumerable<Int64>)

Int64 값 시퀀스의 합을 계산합니다.Computes the sum of a sequence of Int64 values.

public:
[System::Runtime::CompilerServices::Extension]
 static long Sum(System::Collections::Generic::IEnumerable<long> ^ source);
public static long Sum (this System.Collections.Generic.IEnumerable<long> source);
static member Sum : seq<int64> -> int64
<Extension()>
Public Function Sum (source As IEnumerable(Of Long)) As Long

매개 변수

source
IEnumerable<Int64>

합을 계산할 Int64 값의 시퀀스입니다.A sequence of Int64 values to calculate the sum of.

반환

시퀀스에 있는 값의 합입니다.The sum of the values in the sequence.

예외

합계가 MaxValue보다 큰 경우The sum is larger than MaxValue.

예제

다음 코드 예제에 사용 하는 방법을 보여 줍니다. Sum(IEnumerable<Single>) 값 시퀀스의 합계입니다.The following code example demonstrates how to use Sum(IEnumerable<Single>) to sum the values of a sequence.

참고

이 코드 예제에서는 이 항목에서 설명하는 특정 오버로드와는 다른 이 오버로드된 메서드의 오버로드를 사용합니다.This code example uses an overload of this overloaded method that is different from the specific overload that this topic describes. 이 항목의 예제를 확장하려면 소스 시퀀스의 요소를 적절한 숫자 형식의 요소로 대체하십시오.To extend the example to this topic, substitute the elements of the source sequence with elements of the appropriate numerical type.

List<float> numbers = new List<float> { 43.68F, 1.25F, 583.7F, 6.5F };

float sum = numbers.Sum();

Console.WriteLine("The sum of the numbers is {0}.", sum);

/*
 This code produces the following output:

 The sum of the numbers is 635.13.
*/
' Create a list of Single values.
Dim numbers As New List(Of Single)(New Single() _
                               {43.68F, 1.25F, 583.7F, 6.5F})

' Get the sum of values in the list.
Dim sum As Single = numbers.Sum()

' Display the output.
MsgBox("The sum of the numbers is " & sum)

' This code produces the following output:
'
' The sum of the numbers is 635.13

설명

이 메서드는 경우 0을 반환 source 요소가 없는.This method returns zero if source contains no elements.

Visual Basic 쿼리 식 구문에는 Aggregate Into Sum() 절 뒤에 변환 Sum합니다.In Visual Basic query expression syntax, an Aggregate Into Sum() clause translates to an invocation of Sum.

추가 정보

Sum(IEnumerable<Int32>) Sum(IEnumerable<Int32>) Sum(IEnumerable<Int32>) Sum(IEnumerable<Int32>)

Int32 값 시퀀스의 합을 계산합니다.Computes the sum of a sequence of Int32 values.

public:
[System::Runtime::CompilerServices::Extension]
 static int Sum(System::Collections::Generic::IEnumerable<int> ^ source);
public static int Sum (this System.Collections.Generic.IEnumerable<int> source);
static member Sum : seq<int> -> int
<Extension()>
Public Function Sum (source As IEnumerable(Of Integer)) As Integer

매개 변수

source
IEnumerable<Int32>

합을 계산할 Int32 값의 시퀀스입니다.A sequence of Int32 values to calculate the sum of.

반환

시퀀스에 있는 값의 합입니다.The sum of the values in the sequence.

예외

합계가 MaxValue보다 큰 경우The sum is larger than MaxValue.

예제

다음 코드 예제에 사용 하는 방법을 보여 줍니다. Sum(IEnumerable<Single>) 값 시퀀스의 합계입니다.The following code example demonstrates how to use Sum(IEnumerable<Single>) to sum the values of a sequence.

참고

이 코드 예제에서는 이 항목에서 설명하는 특정 오버로드와는 다른 이 오버로드된 메서드의 오버로드를 사용합니다.This code example uses an overload of this overloaded method that is different from the specific overload that this topic describes. 이 항목의 예제를 확장하려면 소스 시퀀스의 요소를 적절한 숫자 형식의 요소로 대체하십시오.To extend the example to this topic, substitute the elements of the source sequence with elements of the appropriate numerical type.

List<float> numbers = new List<float> { 43.68F, 1.25F, 583.7F, 6.5F };

float sum = numbers.Sum();

Console.WriteLine("The sum of the numbers is {0}.", sum);

/*
 This code produces the following output:

 The sum of the numbers is 635.13.
*/
' Create a list of Single values.
Dim numbers As New List(Of Single)(New Single() _
                               {43.68F, 1.25F, 583.7F, 6.5F})

' Get the sum of values in the list.
Dim sum As Single = numbers.Sum()

' Display the output.
MsgBox("The sum of the numbers is " & sum)

' This code produces the following output:
'
' The sum of the numbers is 635.13

설명

이 메서드는 경우 0을 반환 source 요소가 없는.This method returns zero if source contains no elements.

Visual Basic 쿼리 식 구문에는 Aggregate Into Sum() 절 뒤에 변환 Sum합니다.In Visual Basic query expression syntax, an Aggregate Into Sum() clause translates to an invocation of Sum.

추가 정보

Sum(IEnumerable<Decimal>) Sum(IEnumerable<Decimal>) Sum(IEnumerable<Decimal>) Sum(IEnumerable<Decimal>)

Decimal 값 시퀀스의 합을 계산합니다.Computes the sum of a sequence of Decimal values.

public:
[System::Runtime::CompilerServices::Extension]
 static System::Decimal Sum(System::Collections::Generic::IEnumerable<System::Decimal> ^ source);
public static decimal Sum (this System.Collections.Generic.IEnumerable<decimal> source);
static member Sum : seq<decimal> -> decimal
<Extension()>
Public Function Sum (source As IEnumerable(Of Decimal)) As Decimal

매개 변수

source
IEnumerable<Decimal>

합을 계산할 Decimal 값의 시퀀스입니다.A sequence of Decimal values to calculate the sum of.

반환

시퀀스에 있는 값의 합입니다.The sum of the values in the sequence.

예외

합계가 MaxValue보다 큰 경우The sum is larger than MaxValue.

예제

다음 코드 예제에 사용 하는 방법을 보여 줍니다. Sum(IEnumerable<Single>) 값 시퀀스의 합계입니다.The following code example demonstrates how to use Sum(IEnumerable<Single>) to sum the values of a sequence.

참고

이 코드 예제에서는 이 항목에서 설명하는 특정 오버로드와는 다른 이 오버로드된 메서드의 오버로드를 사용합니다.This code example uses an overload of this overloaded method that is different from the specific overload that this topic describes. 이 항목의 예제를 확장하려면 소스 시퀀스의 요소를 적절한 숫자 형식의 요소로 대체하십시오.To extend the example to this topic, substitute the elements of the source sequence with elements of the appropriate numerical type.

List<float> numbers = new List<float> { 43.68F, 1.25F, 583.7F, 6.5F };

float sum = numbers.Sum();

Console.WriteLine("The sum of the numbers is {0}.", sum);

/*
 This code produces the following output:

 The sum of the numbers is 635.13.
*/
' Create a list of Single values.
Dim numbers As New List(Of Single)(New Single() _
                               {43.68F, 1.25F, 583.7F, 6.5F})

' Get the sum of values in the list.
Dim sum As Single = numbers.Sum()

' Display the output.
MsgBox("The sum of the numbers is " & sum)

' This code produces the following output:
'
' The sum of the numbers is 635.13

설명

합니다 Sum(IEnumerable<Decimal>) 경우 0을 반환 하는 메서드 source 요소가 없는.The Sum(IEnumerable<Decimal>) method returns zero if source contains no elements.

Visual Basic 쿼리 식 구문에는 Aggregate Into Sum() 절 뒤에 변환 Sum합니다.In Visual Basic query expression syntax, an Aggregate Into Sum() clause translates to an invocation of Sum.

추가 정보

Sum(IEnumerable<Nullable<Decimal>>) Sum(IEnumerable<Nullable<Decimal>>) Sum(IEnumerable<Nullable<Decimal>>) Sum(IEnumerable<Nullable<Decimal>>)

nullable Decimal 값 시퀀스의 합을 계산합니다.Computes the sum of a sequence of nullable Decimal values.

public:
[System::Runtime::CompilerServices::Extension]
 static Nullable<System::Decimal> Sum(System::Collections::Generic::IEnumerable<Nullable<System::Decimal>> ^ source);
public static Nullable<decimal> Sum (this System.Collections.Generic.IEnumerable<Nullable<decimal>> source);
static member Sum : seq<Nullable<decimal>> -> Nullable<decimal>
<Extension()>
Public Function Sum (source As IEnumerable(Of Nullable(Of Decimal))) As Nullable(Of Decimal)

매개 변수

source
IEnumerable<Nullable<Decimal>>

합을 계산할 nullable Decimal 값의 시퀀스입니다.A sequence of nullable Decimal values to calculate the sum of.

반환

시퀀스에 있는 값의 합입니다.The sum of the values in the sequence.

예외

합계가 MaxValue보다 큰 경우The sum is larger than MaxValue.

예제

다음 코드 예제에 사용 하는 방법을 보여 줍니다. Sum(IEnumerable<Nullable<Single>>) 값 시퀀스의 합계입니다.The following code example demonstrates how to use Sum(IEnumerable<Nullable<Single>>) to sum the values of a sequence.

참고

이 코드 예제에서는 이 항목에서 설명하는 특정 오버로드와는 다른 이 오버로드된 메서드의 오버로드를 사용합니다.This code example uses an overload of this overloaded method that is different from the specific overload that this topic describes. 이 항목의 예제를 확장하려면 소스 시퀀스의 요소를 적절한 숫자 형식의 요소로 대체하십시오.To extend the example to this topic, substitute the elements of the source sequence with elements of the appropriate numerical type.

float?[] points = { null, 0, 92.83F, null, 100.0F, 37.46F, 81.1F };

float? sum = points.Sum();

Console.WriteLine("Total points earned: {0}", sum);

/*
 This code produces the following output:

 Total points earned: 311.39
*/
' Create an array of Nullable Single values.
Dim points() As Nullable(Of Single) =
{Nothing, 0, 92.83F, Nothing, 100.0F, 37.46F, 81.1F}

' Get the sum of values in the list.
Dim sum As Nullable(Of Single) = points.Sum()

' Display the output.
MsgBox("Total points earned: " & sum)

' This code produces the following output:
'
' Total points earned: 311.39

설명

이 메서드는 경우 0을 반환 source 요소가 없는.This method returns zero if source contains no elements.

값을 포함 하는 결과 하지 않습니다 null합니다.The result doesnot include values that are null.

Visual Basic 쿼리 식 구문에는 Aggregate Into Sum() 절 뒤에 변환 Sum합니다.In Visual Basic query expression syntax, an Aggregate Into Sum() clause translates to an invocation of Sum.

추가 정보

Sum<TSource>(IEnumerable<TSource>, Func<TSource,Single>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Single>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Single>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Single>)

입력 시퀀스의 각 요소에 대해 변형 함수를 호출하여 가져온 Single 값 시퀀스의 합을 계산합니다.Computes the sum of the sequence of Single values that are obtained by invoking a transform function on each element of the input sequence.

public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
 static float Sum(System::Collections::Generic::IEnumerable<TSource> ^ source, Func<TSource, float> ^ selector);
public static float Sum<TSource> (this System.Collections.Generic.IEnumerable<TSource> source, Func<TSource,float> selector);
static member Sum : seq<'Source> * Func<'Source, single> -> single
<Extension()>
Public Function Sum(Of TSource) (source As IEnumerable(Of TSource), selector As Func(Of TSource, Single)) As Single

형식 매개 변수

TSource

source 요소의 형식입니다.The type of the elements of source.

매개 변수

source
IEnumerable<TSource>

합을 계산하는 데 사용되는 값의 시퀀스입니다.A sequence of values that are used to calculate a sum.

selector
Func<TSource,Single>

각 요소에 적용할 변환 함수입니다.A transform function to apply to each element.

반환

투영된 값의 합입니다.The sum of the projected values.

예외

source 또는 selectornull인 경우source or selector is null.

예제

다음 코드 예제에 사용 하는 방법을 보여 줍니다. Sum<TSource>(IEnumerable<TSource>, Func<TSource,Double>) 프로젝션된 된 값 시퀀스의 합계입니다.The following code example demonstrates how to use Sum<TSource>(IEnumerable<TSource>, Func<TSource,Double>) to sum the projected values of a sequence.

참고

이 코드 예제에서는 이 항목에서 설명하는 특정 오버로드와는 다른 이 오버로드된 메서드의 오버로드를 사용합니다.This code example uses an overload of this overloaded method that is different from the specific overload that this topic describes. 이 항목의 예제를 확장하려면 selector 함수의 본문을 변경하세요.To extend the example to this topic, change the body of the selector function.

class Package
{
    public string Company { get; set; }
    public double Weight { get; set; }
}

public static void SumEx1()
{
    List<Package> packages =
        new List<Package> 
            { new Package { Company = "Coho Vineyard", Weight = 25.2 },
              new Package { Company = "Lucerne Publishing", Weight = 18.7 },
              new Package { Company = "Wingtip Toys", Weight = 6.0 },
              new Package { Company = "Adventure Works", Weight = 33.8 } };

    double totalWeight = packages.Sum(pkg => pkg.Weight);

    Console.WriteLine("The total weight of the packages is: {0}", totalWeight);
}

/*
 This code produces the following output:

 The total weight of the packages is: 83.7
*/
Structure Package
    Public Company As String
    Public Weight As Double
End Structure

Sub SumEx1()
    ' Create a list of Package values.
    Dim packages As New List(Of Package)(New Package() _
     {New Package With {.Company = "Coho Vineyard", .Weight = 25.2},
      New Package With {.Company = "Lucerne Publishing", .Weight = 18.7},
      New Package With {.Company = "Wingtip Toys", .Weight = 6.0},
      New Package With {.Company = "Adventure Works", .Weight = 33.8}})

    ' Sum the values from each item's Weight property.
    Dim totalWeight As Double = packages.Sum(Function(pkg) _
                                             pkg.Weight)

    ' Display the result.
    MsgBox("The total weight of the packages is: " & totalWeight)
End Sub

' This code produces the following output:
'
' The total weight of the packages is: 83.7

설명

합니다 Sum<TSource>(IEnumerable<TSource>, Func<TSource,Single>) 경우 0을 반환 하는 메서드 source 요소가 없는.The Sum<TSource>(IEnumerable<TSource>, Func<TSource,Single>) method returns zero if source contains no elements.

함수를 제공 하는 경우 임의의 값 시퀀스로이 메서드를 적용할 수 있습니다 selector에 프로젝트의 멤버 source 숫자 형식으로 특히 Single합니다.You can apply this method to a sequence of arbitrary values if you provide a function, selector, that projects the members of source into a numeric type, specifically Single.

Visual Basic 쿼리 식 구문에는 Aggregate Into Sum() 절 뒤에 변환 Sum합니다.In Visual Basic query expression syntax, an Aggregate Into Sum() clause translates to an invocation of Sum.

추가 정보

Sum<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Single>>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Single>>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Single>>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Single>>)

입력 시퀀스의 각 요소에 대해 변형 함수를 호출하여 가져온 nullable Single 값 시퀀스의 합을 계산합니다.Computes the sum of the sequence of nullable Single values that are obtained by invoking a transform function on each element of the input sequence.

public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
 static Nullable<float> Sum(System::Collections::Generic::IEnumerable<TSource> ^ source, Func<TSource, Nullable<float>> ^ selector);
public static Nullable<float> Sum<TSource> (this System.Collections.Generic.IEnumerable<TSource> source, Func<TSource,Nullable<float>> selector);
static member Sum : seq<'Source> * Func<'Source, Nullable<single>> -> Nullable<single>
<Extension()>
Public Function Sum(Of TSource) (source As IEnumerable(Of TSource), selector As Func(Of TSource, Nullable(Of Single))) As Nullable(Of Single)

형식 매개 변수

TSource

source 요소의 형식입니다.The type of the elements of source.

매개 변수

source
IEnumerable<TSource>

합을 계산하는 데 사용되는 값의 시퀀스입니다.A sequence of values that are used to calculate a sum.

selector
Func<TSource,Nullable<Single>>

각 요소에 적용할 변환 함수입니다.A transform function to apply to each element.

반환

투영된 값의 합입니다.The sum of the projected values.

예외

source 또는 selectornull인 경우source or selector is null.

예제

다음 코드 예제에 사용 하는 방법을 보여 줍니다. Sum<TSource>(IEnumerable<TSource>, Func<TSource,Double>) 프로젝션된 된 값 시퀀스의 합계입니다.The following code example demonstrates how to use Sum<TSource>(IEnumerable<TSource>, Func<TSource,Double>) to sum the projected values of a sequence.

참고

이 코드 예제에서는 이 항목에서 설명하는 특정 오버로드와는 다른 이 오버로드된 메서드의 오버로드를 사용합니다.This code example uses an overload of this overloaded method that is different from the specific overload that this topic describes. 이 항목의 예제를 확장하려면 selector 함수의 본문을 변경하세요.To extend the example to this topic, change the body of the selector function.

class Package
{
    public string Company { get; set; }
    public double Weight { get; set; }
}

public static void SumEx1()
{
    List<Package> packages =
        new List<Package> 
            { new Package { Company = "Coho Vineyard", Weight = 25.2 },
              new Package { Company = "Lucerne Publishing", Weight = 18.7 },
              new Package { Company = "Wingtip Toys", Weight = 6.0 },
              new Package { Company = "Adventure Works", Weight = 33.8 } };

    double totalWeight = packages.Sum(pkg => pkg.Weight);

    Console.WriteLine("The total weight of the packages is: {0}", totalWeight);
}

/*
 This code produces the following output:

 The total weight of the packages is: 83.7
*/
Structure Package
    Public Company As String
    Public Weight As Double
End Structure

Sub SumEx1()
    ' Create a list of Package values.
    Dim packages As New List(Of Package)(New Package() _
     {New Package With {.Company = "Coho Vineyard", .Weight = 25.2},
      New Package With {.Company = "Lucerne Publishing", .Weight = 18.7},
      New Package With {.Company = "Wingtip Toys", .Weight = 6.0},
      New Package With {.Company = "Adventure Works", .Weight = 33.8}})

    ' Sum the values from each item's Weight property.
    Dim totalWeight As Double = packages.Sum(Function(pkg) _
                                             pkg.Weight)

    ' Display the result.
    MsgBox("The total weight of the packages is: " & totalWeight)
End Sub

' This code produces the following output:
'
' The total weight of the packages is: 83.7

설명

이 메서드는 경우 0을 반환 source 요소가 없는.This method returns zero if source contains no elements.

결과 값을 포함 하지 않습니다 null합니다.The result does not include values that are null.

함수를 제공 하는 경우 임의의 값 시퀀스로이 메서드를 적용할 수 있습니다 selector, 하는 프로젝트의 멤버 source 숫자 형식으로 특히 Nullable<Single> C# 또는 Nullable(Of Single) Visual Basic의 합니다.You can apply this method to a sequence of arbitrary values if you provide a function, selector, that projects the members of source into a numeric type, specifically Nullable<Single> in C# or Nullable(Of Single) in Visual Basic.

Visual Basic 쿼리 식 구문에는 Aggregate Into Sum() 절 뒤에 변환 Sum합니다.In Visual Basic query expression syntax, an Aggregate Into Sum() clause translates to an invocation of Sum.

추가 정보

Sum<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Int64>>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Int64>>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Int64>>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Int64>>)

입력 시퀀스의 각 요소에 대해 변형 함수를 호출하여 가져온 nullable Int64 값 시퀀스의 합을 계산합니다.Computes the sum of the sequence of nullable Int64 values that are obtained by invoking a transform function on each element of the input sequence.

public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
 static Nullable<long> Sum(System::Collections::Generic::IEnumerable<TSource> ^ source, Func<TSource, Nullable<long>> ^ selector);
public static Nullable<long> Sum<TSource> (this System.Collections.Generic.IEnumerable<TSource> source, Func<TSource,Nullable<long>> selector);
static member Sum : seq<'Source> * Func<'Source, Nullable<int64>> -> Nullable<int64>
<Extension()>
Public Function Sum(Of TSource) (source As IEnumerable(Of TSource), selector As Func(Of TSource, Nullable(Of Long))) As Nullable(Of Long)

형식 매개 변수

TSource

source 요소의 형식입니다.The type of the elements of source.

매개 변수

source
IEnumerable<TSource>

합을 계산하는 데 사용되는 값의 시퀀스입니다.A sequence of values that are used to calculate a sum.

selector
Func<TSource,Nullable<Int64>>

각 요소에 적용할 변환 함수입니다.A transform function to apply to each element.

반환

투영된 값의 합입니다.The sum of the projected values.

예외

source 또는 selectornull인 경우source or selector is null.

합계가 MaxValue보다 큰 경우The sum is larger than MaxValue.

예제

다음 코드 예제에 사용 하는 방법을 보여 줍니다. Sum<TSource>(IEnumerable<TSource>, Func<TSource,Double>) 프로젝션된 된 값 시퀀스의 합계입니다.The following code example demonstrates how to use Sum<TSource>(IEnumerable<TSource>, Func<TSource,Double>) to sum the projected values of a sequence.

참고

이 코드 예제에서는 이 항목에서 설명하는 특정 오버로드와는 다른 이 오버로드된 메서드의 오버로드를 사용합니다.This code example uses an overload of this overloaded method that is different from the specific overload that this topic describes. 이 항목의 예제를 확장하려면 selector 함수의 본문을 변경하세요.To extend the example to this topic, change the body of the selector function.

class Package
{
    public string Company { get; set; }
    public double Weight { get; set; }
}

public static void SumEx1()
{
    List<Package> packages =
        new List<Package> 
            { new Package { Company = "Coho Vineyard", Weight = 25.2 },
              new Package { Company = "Lucerne Publishing", Weight = 18.7 },
              new Package { Company = "Wingtip Toys", Weight = 6.0 },
              new Package { Company = "Adventure Works", Weight = 33.8 } };

    double totalWeight = packages.Sum(pkg => pkg.Weight);

    Console.WriteLine("The total weight of the packages is: {0}", totalWeight);
}

/*
 This code produces the following output:

 The total weight of the packages is: 83.7
*/
Structure Package
    Public Company As String
    Public Weight As Double
End Structure

Sub SumEx1()
    ' Create a list of Package values.
    Dim packages As New List(Of Package)(New Package() _
     {New Package With {.Company = "Coho Vineyard", .Weight = 25.2},
      New Package With {.Company = "Lucerne Publishing", .Weight = 18.7},
      New Package With {.Company = "Wingtip Toys", .Weight = 6.0},
      New Package With {.Company = "Adventure Works", .Weight = 33.8}})

    ' Sum the values from each item's Weight property.
    Dim totalWeight As Double = packages.Sum(Function(pkg) _
                                             pkg.Weight)

    ' Display the result.
    MsgBox("The total weight of the packages is: " & totalWeight)
End Sub

' This code produces the following output:
'
' The total weight of the packages is: 83.7

설명

이 메서드는 경우 0을 반환 source 요소가 없는.This method returns zero if source contains no elements.

결과 값을 포함 하지 않습니다 null합니다.The result does not include values that are null.

함수를 제공 하는 경우 임의의 값 시퀀스로이 메서드를 적용할 수 있습니다 selector에 프로젝트의 멤버 source 숫자 형식으로 특히 Nullable<Int64> C# 또는 Nullable(Of Int64) Visual Basic의You can apply this method to a sequence of arbitrary values if you provide a function, selector, that projects the members of source into a numeric type, specifically Nullable<Int64> in C# or Nullable(Of Int64) in Visual Basic

Visual Basic 쿼리 식 구문에는 Aggregate Into Sum() 절 뒤에 변환 Sum합니다.In Visual Basic query expression syntax, an Aggregate Into Sum() clause translates to an invocation of Sum.

추가 정보

Sum<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Int32>>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Int32>>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Int32>>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Int32>>)

입력 시퀀스의 각 요소에 대해 변형 함수를 호출하여 가져온 nullable Int32 값 시퀀스의 합을 계산합니다.Computes the sum of the sequence of nullable Int32 values that are obtained by invoking a transform function on each element of the input sequence.

public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
 static Nullable<int> Sum(System::Collections::Generic::IEnumerable<TSource> ^ source, Func<TSource, Nullable<int>> ^ selector);
public static Nullable<int> Sum<TSource> (this System.Collections.Generic.IEnumerable<TSource> source, Func<TSource,Nullable<int>> selector);
static member Sum : seq<'Source> * Func<'Source, Nullable<int>> -> Nullable<int>
<Extension()>
Public Function Sum(Of TSource) (source As IEnumerable(Of TSource), selector As Func(Of TSource, Nullable(Of Integer))) As Nullable(Of Integer)

형식 매개 변수

TSource

source 요소의 형식입니다.The type of the elements of source.

매개 변수

source
IEnumerable<TSource>

합을 계산하는 데 사용되는 값의 시퀀스입니다.A sequence of values that are used to calculate a sum.

selector
Func<TSource,Nullable<Int32>>

각 요소에 적용할 변환 함수입니다.A transform function to apply to each element.

반환

투영된 값의 합입니다.The sum of the projected values.

예외

source 또는 selectornull인 경우source or selector is null.

합계가 MaxValue보다 큰 경우The sum is larger than MaxValue.

예제

다음 코드 예제에 사용 하는 방법을 보여 줍니다. Sum<TSource>(IEnumerable<TSource>, Func<TSource,Double>) 프로젝션된 된 값 시퀀스의 합계입니다.The following code example demonstrates how to use Sum<TSource>(IEnumerable<TSource>, Func<TSource,Double>) to sum the projected values of a sequence.

참고

이 코드 예제에서는 이 항목에서 설명하는 특정 오버로드와는 다른 이 오버로드된 메서드의 오버로드를 사용합니다.This code example uses an overload of this overloaded method that is different from the specific overload that this topic describes. 이 항목의 예제를 확장하려면 selector 함수의 본문을 변경하세요.To extend the example to this topic, change the body of the selector function.

class Package
{
    public string Company { get; set; }
    public double Weight { get; set; }
}

public static void SumEx1()
{
    List<Package> packages =
        new List<Package> 
            { new Package { Company = "Coho Vineyard", Weight = 25.2 },
              new Package { Company = "Lucerne Publishing", Weight = 18.7 },
              new Package { Company = "Wingtip Toys", Weight = 6.0 },
              new Package { Company = "Adventure Works", Weight = 33.8 } };

    double totalWeight = packages.Sum(pkg => pkg.Weight);

    Console.WriteLine("The total weight of the packages is: {0}", totalWeight);
}

/*
 This code produces the following output:

 The total weight of the packages is: 83.7
*/
Structure Package
    Public Company As String
    Public Weight As Double
End Structure

Sub SumEx1()
    ' Create a list of Package values.
    Dim packages As New List(Of Package)(New Package() _
     {New Package With {.Company = "Coho Vineyard", .Weight = 25.2},
      New Package With {.Company = "Lucerne Publishing", .Weight = 18.7},
      New Package With {.Company = "Wingtip Toys", .Weight = 6.0},
      New Package With {.Company = "Adventure Works", .Weight = 33.8}})

    ' Sum the values from each item's Weight property.
    Dim totalWeight As Double = packages.Sum(Function(pkg) _
                                             pkg.Weight)

    ' Display the result.
    MsgBox("The total weight of the packages is: " & totalWeight)
End Sub

' This code produces the following output:
'
' The total weight of the packages is: 83.7

설명

이 메서드는 경우 0을 반환 source 요소가 없는.This method returns zero if source contains no elements.

결과 값을 포함 하지 않습니다 null합니다.The result does not include values that are null.

함수를 제공 하는 경우 임의의 값 시퀀스로이 메서드를 적용할 수 있습니다 selector, 하는 프로젝트의 멤버 source 숫자 형식으로 특히 Nullable<Int32> C# 또는 Nullable(Of Int32) Visual Basic의 합니다.You can apply this method to a sequence of arbitrary values if you provide a function, selector, that projects the members of source into a numeric type, specifically Nullable<Int32> in C# or Nullable(Of Int32) in Visual Basic.

Visual Basic 쿼리 식 구문에는 Aggregate Into Sum() 절 뒤에 변환 Sum합니다.In Visual Basic query expression syntax, an Aggregate Into Sum() clause translates to an invocation of Sum.

추가 정보

Sum<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Double>>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Double>>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Double>>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Double>>)

입력 시퀀스의 각 요소에 대해 변형 함수를 호출하여 가져온 nullable Double 값 시퀀스의 합을 계산합니다.Computes the sum of the sequence of nullable Double values that are obtained by invoking a transform function on each element of the input sequence.

public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
 static Nullable<double> Sum(System::Collections::Generic::IEnumerable<TSource> ^ source, Func<TSource, Nullable<double>> ^ selector);
public static Nullable<double> Sum<TSource> (this System.Collections.Generic.IEnumerable<TSource> source, Func<TSource,Nullable<double>> selector);
static member Sum : seq<'Source> * Func<'Source, Nullable<double>> -> Nullable<double>
<Extension()>
Public Function Sum(Of TSource) (source As IEnumerable(Of TSource), selector As Func(Of TSource, Nullable(Of Double))) As Nullable(Of Double)

형식 매개 변수

TSource

source 요소의 형식입니다.The type of the elements of source.

매개 변수

source
IEnumerable<TSource>

합을 계산하는 데 사용되는 값의 시퀀스입니다.A sequence of values that are used to calculate a sum.

selector
Func<TSource,Nullable<Double>>

각 요소에 적용할 변환 함수입니다.A transform function to apply to each element.

반환

투영된 값의 합입니다.The sum of the projected values.

예외

source 또는 selectornull인 경우source or selector is null.

예제

다음 코드 예제에 사용 하는 방법을 보여 줍니다. Sum<TSource>(IEnumerable<TSource>, Func<TSource,Double>) 프로젝션된 된 값 시퀀스의 합계입니다.The following code example demonstrates how to use Sum<TSource>(IEnumerable<TSource>, Func<TSource,Double>) to sum the projected values of a sequence.

참고

이 코드 예제에서는 이 항목에서 설명하는 특정 오버로드와는 다른 이 오버로드된 메서드의 오버로드를 사용합니다.This code example uses an overload of this overloaded method that is different from the specific overload that this topic describes. 이 항목의 예제를 확장하려면 selector 함수의 본문을 변경하세요.To extend the example to this topic, change the body of the selector function.

class Package
{
    public string Company { get; set; }
    public double Weight { get; set; }
}

public static void SumEx1()
{
    List<Package> packages =
        new List<Package> 
            { new Package { Company = "Coho Vineyard", Weight = 25.2 },
              new Package { Company = "Lucerne Publishing", Weight = 18.7 },
              new Package { Company = "Wingtip Toys", Weight = 6.0 },
              new Package { Company = "Adventure Works", Weight = 33.8 } };

    double totalWeight = packages.Sum(pkg => pkg.Weight);

    Console.WriteLine("The total weight of the packages is: {0}", totalWeight);
}

/*
 This code produces the following output:

 The total weight of the packages is: 83.7
*/
Structure Package
    Public Company As String
    Public Weight As Double
End Structure

Sub SumEx1()
    ' Create a list of Package values.
    Dim packages As New List(Of Package)(New Package() _
     {New Package With {.Company = "Coho Vineyard", .Weight = 25.2},
      New Package With {.Company = "Lucerne Publishing", .Weight = 18.7},
      New Package With {.Company = "Wingtip Toys", .Weight = 6.0},
      New Package With {.Company = "Adventure Works", .Weight = 33.8}})

    ' Sum the values from each item's Weight property.
    Dim totalWeight As Double = packages.Sum(Function(pkg) _
                                             pkg.Weight)

    ' Display the result.
    MsgBox("The total weight of the packages is: " & totalWeight)
End Sub

' This code produces the following output:
'
' The total weight of the packages is: 83.7

설명

이 메서드는 경우 0을 반환 source 요소가 없는.This method returns zero if source contains no elements.

결과 값을 포함 하지 않습니다 null합니다.The result does not include values that are null.

함수를 제공 하는 경우 임의의 값 시퀀스로이 메서드를 적용할 수 있습니다 selector, 하는 프로젝트의 멤버 source 숫자 형식으로 특히 Nullable<Double> C# 또는 Nullable(Of Double) Visual Basic의 합니다.You can apply this method to a sequence of arbitrary values if you provide a function, selector, that projects the members of source into a numeric type, specifically Nullable<Double> in C# or Nullable(Of Double) in Visual Basic.

Visual Basic 쿼리 식 구문에는 Aggregate Into Sum() 절 뒤에 변환 Sum합니다.In Visual Basic query expression syntax, an Aggregate Into Sum() clause translates to an invocation of Sum.

추가 정보

Sum<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Decimal>>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Decimal>>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Decimal>>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Nullable<Decimal>>)

입력 시퀀스의 각 요소에 대해 변형 함수를 호출하여 가져온 nullable Decimal 값 시퀀스의 합을 계산합니다.Computes the sum of the sequence of nullable Decimal values that are obtained by invoking a transform function on each element of the input sequence.

public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
 static Nullable<System::Decimal> Sum(System::Collections::Generic::IEnumerable<TSource> ^ source, Func<TSource, Nullable<System::Decimal>> ^ selector);
public static Nullable<decimal> Sum<TSource> (this System.Collections.Generic.IEnumerable<TSource> source, Func<TSource,Nullable<decimal>> selector);
static member Sum : seq<'Source> * Func<'Source, Nullable<decimal>> -> Nullable<decimal>
<Extension()>
Public Function Sum(Of TSource) (source As IEnumerable(Of TSource), selector As Func(Of TSource, Nullable(Of Decimal))) As Nullable(Of Decimal)

형식 매개 변수

TSource

source 요소의 형식입니다.The type of the elements of source.

매개 변수

source
IEnumerable<TSource>

합을 계산하는 데 사용되는 값의 시퀀스입니다.A sequence of values that are used to calculate a sum.

selector
Func<TSource,Nullable<Decimal>>

각 요소에 적용할 변환 함수입니다.A transform function to apply to each element.

반환

투영된 값의 합입니다.The sum of the projected values.

예외

source 또는 selectornull인 경우source or selector is null.

합계가 MaxValue보다 큰 경우The sum is larger than MaxValue.

예제

다음 코드 예제에 사용 하는 방법을 보여 줍니다. Sum<TSource>(IEnumerable<TSource>, Func<TSource,Double>) 프로젝션된 된 값 시퀀스의 합계입니다.The following code example demonstrates how to use Sum<TSource>(IEnumerable<TSource>, Func<TSource,Double>) to sum the projected values of a sequence.

참고

이 코드 예제에서는 이 항목에서 설명하는 특정 오버로드와는 다른 이 오버로드된 메서드의 오버로드를 사용합니다.This code example uses an overload of this overloaded method that is different from the specific overload that this topic describes. 이 항목의 예제를 확장하려면 selector 함수의 본문을 변경하세요.To extend the example to this topic, change the body of the selector function.

class Package
{
    public string Company { get; set; }
    public double Weight { get; set; }
}

public static void SumEx1()
{
    List<Package> packages =
        new List<Package> 
            { new Package { Company = "Coho Vineyard", Weight = 25.2 },
              new Package { Company = "Lucerne Publishing", Weight = 18.7 },
              new Package { Company = "Wingtip Toys", Weight = 6.0 },
              new Package { Company = "Adventure Works", Weight = 33.8 } };

    double totalWeight = packages.Sum(pkg => pkg.Weight);

    Console.WriteLine("The total weight of the packages is: {0}", totalWeight);
}

/*
 This code produces the following output:

 The total weight of the packages is: 83.7
*/
Structure Package
    Public Company As String
    Public Weight As Double
End Structure

Sub SumEx1()
    ' Create a list of Package values.
    Dim packages As New List(Of Package)(New Package() _
     {New Package With {.Company = "Coho Vineyard", .Weight = 25.2},
      New Package With {.Company = "Lucerne Publishing", .Weight = 18.7},
      New Package With {.Company = "Wingtip Toys", .Weight = 6.0},
      New Package With {.Company = "Adventure Works", .Weight = 33.8}})

    ' Sum the values from each item's Weight property.
    Dim totalWeight As Double = packages.Sum(Function(pkg) _
                                             pkg.Weight)

    ' Display the result.
    MsgBox("The total weight of the packages is: " & totalWeight)
End Sub

' This code produces the following output:
'
' The total weight of the packages is: 83.7

설명

이 메서드는 경우 0을 반환 source 요소가 없는.This method returns zero if source contains no elements.

결과 값은 포함 되지 않습니다 null합니다.The result does not included values that are null.

함수를 제공 하는 경우 임의의 값 시퀀스로이 메서드를 적용할 수 있습니다 selector, 하는 프로젝트의 멤버 source 숫자 형식으로 특히 Nullable<Decimal> C# 또는 Nullable(Of Decimal) Visual Basic의 합니다.You can apply this method to a sequence of arbitrary values if you provide a function, selector, that projects the members of source into a numeric type, specifically Nullable<Decimal> in C# or Nullable(Of Decimal) in Visual Basic.

Visual Basic 쿼리 식 구문에는 Aggregate Into Sum() 절 뒤에 변환 Sum합니다.In Visual Basic query expression syntax, an Aggregate Into Sum() clause translates to an invocation of Sum.

추가 정보

Sum<TSource>(IEnumerable<TSource>, Func<TSource,Int64>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Int64>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Int64>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Int64>)

입력 시퀀스의 각 요소에 대해 변형 함수를 호출하여 가져온 Int64 값 시퀀스의 합을 계산합니다.Computes the sum of the sequence of Int64 values that are obtained by invoking a transform function on each element of the input sequence.

public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
 static long Sum(System::Collections::Generic::IEnumerable<TSource> ^ source, Func<TSource, long> ^ selector);
public static long Sum<TSource> (this System.Collections.Generic.IEnumerable<TSource> source, Func<TSource,long> selector);
static member Sum : seq<'Source> * Func<'Source, int64> -> int64
<Extension()>
Public Function Sum(Of TSource) (source As IEnumerable(Of TSource), selector As Func(Of TSource, Long)) As Long

형식 매개 변수

TSource

source 요소의 형식입니다.The type of the elements of source.

매개 변수

source
IEnumerable<TSource>

합을 계산하는 데 사용되는 값의 시퀀스입니다.A sequence of values that are used to calculate a sum.

selector
Func<TSource,Int64>

각 요소에 적용할 변환 함수입니다.A transform function to apply to each element.

반환

투영된 값의 합입니다.The sum of the projected values.

예외

source 또는 selectornull인 경우source or selector is null.

합계가 MaxValue보다 큰 경우The sum is larger than MaxValue.

예제

다음 코드 예제에 사용 하는 방법을 보여 줍니다. Sum<TSource>(IEnumerable<TSource>, Func<TSource,Double>) 프로젝션된 된 값 시퀀스의 합계입니다.The following code example demonstrates how to use Sum<TSource>(IEnumerable<TSource>, Func<TSource,Double>) to sum the projected values of a sequence.

참고

이 코드 예제에서는 이 항목에서 설명하는 특정 오버로드와는 다른 이 오버로드된 메서드의 오버로드를 사용합니다.This code example uses an overload of this overloaded method that is different from the specific overload that this topic describes. 이 항목의 예제를 확장하려면 selector 함수의 본문을 변경하세요.To extend the example to this topic, change the body of the selector function.

class Package
{
    public string Company { get; set; }
    public double Weight { get; set; }
}

public static void SumEx1()
{
    List<Package> packages =
        new List<Package> 
            { new Package { Company = "Coho Vineyard", Weight = 25.2 },
              new Package { Company = "Lucerne Publishing", Weight = 18.7 },
              new Package { Company = "Wingtip Toys", Weight = 6.0 },
              new Package { Company = "Adventure Works", Weight = 33.8 } };

    double totalWeight = packages.Sum(pkg => pkg.Weight);

    Console.WriteLine("The total weight of the packages is: {0}", totalWeight);
}

/*
 This code produces the following output:

 The total weight of the packages is: 83.7
*/
Structure Package
    Public Company As String
    Public Weight As Double
End Structure

Sub SumEx1()
    ' Create a list of Package values.
    Dim packages As New List(Of Package)(New Package() _
     {New Package With {.Company = "Coho Vineyard", .Weight = 25.2},
      New Package With {.Company = "Lucerne Publishing", .Weight = 18.7},
      New Package With {.Company = "Wingtip Toys", .Weight = 6.0},
      New Package With {.Company = "Adventure Works", .Weight = 33.8}})

    ' Sum the values from each item's Weight property.
    Dim totalWeight As Double = packages.Sum(Function(pkg) _
                                             pkg.Weight)

    ' Display the result.
    MsgBox("The total weight of the packages is: " & totalWeight)
End Sub

' This code produces the following output:
'
' The total weight of the packages is: 83.7

설명

이 메서드는 경우 0을 반환 source 요소가 없는.This method returns zero if source contains no elements.

함수를 제공 하는 경우 임의의 값 시퀀스로이 메서드를 적용할 수 있습니다 selector에 프로젝트의 멤버 source 숫자 형식으로 특히 Int64합니다.You can apply this method to a sequence of arbitrary values if you provide a function, selector, that projects the members of source into a numeric type, specifically Int64.

Visual Basic 쿼리 식 구문에는 Aggregate Into Sum() 절 뒤에 변환 Sum합니다.In Visual Basic query expression syntax, an Aggregate Into Sum() clause translates to an invocation of Sum.

추가 정보

Sum<TSource>(IEnumerable<TSource>, Func<TSource,Int32>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Int32>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Int32>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Int32>)

입력 시퀀스의 각 요소에 대해 변형 함수를 호출하여 가져온 Int32 값 시퀀스의 합을 계산합니다.Computes the sum of the sequence of Int32 values that are obtained by invoking a transform function on each element of the input sequence.

public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
 static int Sum(System::Collections::Generic::IEnumerable<TSource> ^ source, Func<TSource, int> ^ selector);
public static int Sum<TSource> (this System.Collections.Generic.IEnumerable<TSource> source, Func<TSource,int> selector);
static member Sum : seq<'Source> * Func<'Source, int> -> int
<Extension()>
Public Function Sum(Of TSource) (source As IEnumerable(Of TSource), selector As Func(Of TSource, Integer)) As Integer

형식 매개 변수

TSource

source 요소의 형식입니다.The type of the elements of source.

매개 변수

source
IEnumerable<TSource>

합을 계산하는 데 사용되는 값의 시퀀스입니다.A sequence of values that are used to calculate a sum.

selector
Func<TSource,Int32>

각 요소에 적용할 변환 함수입니다.A transform function to apply to each element.

반환

투영된 값의 합입니다.The sum of the projected values.

예외

source 또는 selectornull인 경우source or selector is null.

합계가 MaxValue보다 큰 경우The sum is larger than MaxValue.

예제

다음 코드 예제에 사용 하는 방법을 보여 줍니다. Sum<TSource>(IEnumerable<TSource>, Func<TSource,Double>) 프로젝션된 된 값 시퀀스의 합계입니다.The following code example demonstrates how to use Sum<TSource>(IEnumerable<TSource>, Func<TSource,Double>) to sum the projected values of a sequence.

참고

이 코드 예제에서는 이 항목에서 설명하는 특정 오버로드와는 다른 이 오버로드된 메서드의 오버로드를 사용합니다.This code example uses an overload of this overloaded method that is different from the specific overload that this topic describes. 이 항목의 예제를 확장하려면 selector 함수의 본문을 변경하세요.To extend the example to this topic, change the body of the selector function.

class Package
{
    public string Company { get; set; }
    public double Weight { get; set; }
}

public static void SumEx1()
{
    List<Package> packages =
        new List<Package> 
            { new Package { Company = "Coho Vineyard", Weight = 25.2 },
              new Package { Company = "Lucerne Publishing", Weight = 18.7 },
              new Package { Company = "Wingtip Toys", Weight = 6.0 },
              new Package { Company = "Adventure Works", Weight = 33.8 } };

    double totalWeight = packages.Sum(pkg => pkg.Weight);

    Console.WriteLine("The total weight of the packages is: {0}", totalWeight);
}

/*
 This code produces the following output:

 The total weight of the packages is: 83.7
*/
Structure Package
    Public Company As String
    Public Weight As Double
End Structure

Sub SumEx1()
    ' Create a list of Package values.
    Dim packages As New List(Of Package)(New Package() _
     {New Package With {.Company = "Coho Vineyard", .Weight = 25.2},
      New Package With {.Company = "Lucerne Publishing", .Weight = 18.7},
      New Package With {.Company = "Wingtip Toys", .Weight = 6.0},
      New Package With {.Company = "Adventure Works", .Weight = 33.8}})

    ' Sum the values from each item's Weight property.
    Dim totalWeight As Double = packages.Sum(Function(pkg) _
                                             pkg.Weight)

    ' Display the result.
    MsgBox("The total weight of the packages is: " & totalWeight)
End Sub

' This code produces the following output:
'
' The total weight of the packages is: 83.7

설명

이 메서드는 경우 0을 반환 source 요소가 없는.This method returns zero if source contains no elements.

함수를 제공 하는 경우 임의의 값 시퀀스로이 메서드를 적용할 수 있습니다 selector에 프로젝트의 멤버 source 숫자 형식으로 특히 Int32합니다.You can apply this method to a sequence of arbitrary values if you provide a function, selector, that projects the members of source into a numeric type, specifically Int32.

Visual Basic 쿼리 식 구문에는 Aggregate Into Sum() 절 뒤에 변환 Sum합니다.In Visual Basic query expression syntax, an Aggregate Into Sum() clause translates to an invocation of Sum.

추가 정보

Sum<TSource>(IEnumerable<TSource>, Func<TSource,Double>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Double>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Double>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Double>)

입력 시퀀스의 각 요소에 대해 변형 함수를 호출하여 가져온 Double 값 시퀀스의 합을 계산합니다.Computes the sum of the sequence of Double values that are obtained by invoking a transform function on each element of the input sequence.

public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
 static double Sum(System::Collections::Generic::IEnumerable<TSource> ^ source, Func<TSource, double> ^ selector);
public static double Sum<TSource> (this System.Collections.Generic.IEnumerable<TSource> source, Func<TSource,double> selector);
static member Sum : seq<'Source> * Func<'Source, double> -> double
<Extension()>
Public Function Sum(Of TSource) (source As IEnumerable(Of TSource), selector As Func(Of TSource, Double)) As Double

형식 매개 변수

TSource

source 요소의 형식입니다.The type of the elements of source.

매개 변수

source
IEnumerable<TSource>

합을 계산하는 데 사용되는 값의 시퀀스입니다.A sequence of values that are used to calculate a sum.

selector
Func<TSource,Double>

각 요소에 적용할 변환 함수입니다.A transform function to apply to each element.

반환

투영된 값의 합입니다.The sum of the projected values.

예외

source 또는 selectornull인 경우source or selector is null.

예제

다음 코드 예제에 사용 하는 방법을 보여 줍니다. Sum<TSource>(IEnumerable<TSource>, Func<TSource,Double>) 프로젝션된 된 값 시퀀스의 합계입니다.The following code example demonstrates how to use Sum<TSource>(IEnumerable<TSource>, Func<TSource,Double>) to sum the projected values of a sequence.

class Package
{
    public string Company { get; set; }
    public double Weight { get; set; }
}

public static void SumEx1()
{
    List<Package> packages =
        new List<Package> 
            { new Package { Company = "Coho Vineyard", Weight = 25.2 },
              new Package { Company = "Lucerne Publishing", Weight = 18.7 },
              new Package { Company = "Wingtip Toys", Weight = 6.0 },
              new Package { Company = "Adventure Works", Weight = 33.8 } };

    double totalWeight = packages.Sum(pkg => pkg.Weight);

    Console.WriteLine("The total weight of the packages is: {0}", totalWeight);
}

/*
 This code produces the following output:

 The total weight of the packages is: 83.7
*/
Structure Package
    Public Company As String
    Public Weight As Double
End Structure

Sub SumEx1()
    ' Create a list of Package values.
    Dim packages As New List(Of Package)(New Package() _
     {New Package With {.Company = "Coho Vineyard", .Weight = 25.2},
      New Package With {.Company = "Lucerne Publishing", .Weight = 18.7},
      New Package With {.Company = "Wingtip Toys", .Weight = 6.0},
      New Package With {.Company = "Adventure Works", .Weight = 33.8}})

    ' Sum the values from each item's Weight property.
    Dim totalWeight As Double = packages.Sum(Function(pkg) _
                                             pkg.Weight)

    ' Display the result.
    MsgBox("The total weight of the packages is: " & totalWeight)
End Sub

' This code produces the following output:
'
' The total weight of the packages is: 83.7

설명

이 메서드는 경우 0을 반환 source 요소가 없는.This method returns zero if source contains no elements.

함수를 제공 하는 경우 임의의 값 시퀀스로이 메서드를 적용할 수 있습니다 selector에 프로젝트의 멤버 source 숫자 형식으로 특히 Double합니다.You can apply this method to a sequence of arbitrary values if you provide a function, selector, that projects the members of source into a numeric type, specifically Double.

Visual Basic 쿼리 식 구문에는 Aggregate Into Sum() 절 뒤에 변환 Sum합니다.In Visual Basic query expression syntax, an Aggregate Into Sum() clause translates to an invocation of Sum.

추가 정보

Sum<TSource>(IEnumerable<TSource>, Func<TSource,Decimal>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Decimal>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Decimal>) Sum<TSource>(IEnumerable<TSource>, Func<TSource,Decimal>)

입력 시퀀스의 각 요소에 대해 변형 함수를 호출하여 가져온 Decimal 값 시퀀스의 합을 계산합니다.Computes the sum of the sequence of Decimal values that are obtained by invoking a transform function on each element of the input sequence.

public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
 static System::Decimal Sum(System::Collections::Generic::IEnumerable<TSource> ^ source, Func<TSource, System::Decimal> ^ selector);
public static decimal Sum<TSource> (this System.Collections.Generic.IEnumerable<TSource> source, Func<TSource,decimal> selector);
static member Sum : seq<'Source> * Func<'Source, decimal> -> decimal
<Extension()>
Public Function Sum(Of TSource) (source As IEnumerable(Of TSource), selector As Func(Of TSource, Decimal)) As Decimal

형식 매개 변수

TSource

source 요소의 형식입니다.The type of the elements of source.

매개 변수

source
IEnumerable<TSource>

합을 계산하는 데 사용되는 값의 시퀀스입니다.A sequence of values that are used to calculate a sum.

selector
Func<TSource,Decimal>

각 요소에 적용할 변환 함수입니다.A transform function to apply to each element.

반환

투영된 값의 합입니다.The sum of the projected values.

예외

source 또는 selectornull인 경우source or selector is null.

합계가 MaxValue보다 큰 경우The sum is larger than MaxValue.

예제

다음 코드 예제에 사용 하는 방법을 보여 줍니다. Sum<TSource>(IEnumerable<TSource>, Func<TSource,Double>) 프로젝션된 된 값 시퀀스의 합계입니다.The following code example demonstrates how to use Sum<TSource>(IEnumerable<TSource>, Func<TSource,Double>) to sum the projected values of a sequence.

참고

이 코드 예제에서는 이 항목에서 설명하는 특정 오버로드와는 다른 이 오버로드된 메서드의 오버로드를 사용합니다.This code example uses an overload of this overloaded method that is different from the specific overload that this topic describes. 이 항목의 예제를 확장하려면 selector 함수의 본문을 변경하세요.To extend the example to this topic, change the body of the selector function.

class Package
{
    public string Company { get; set; }
    public double Weight { get; set; }
}

public static void SumEx1()
{
    List<Package> packages =
        new List<Package> 
            { new Package { Company = "Coho Vineyard", Weight = 25.2 },
              new Package { Company = "Lucerne Publishing", Weight = 18.7 },
              new Package { Company = "Wingtip Toys", Weight = 6.0 },
              new Package { Company = "Adventure Works", Weight = 33.8 } };

    double totalWeight = packages.Sum(pkg => pkg.Weight);

    Console.WriteLine("The total weight of the packages is: {0}", totalWeight);
}

/*
 This code produces the following output:

 The total weight of the packages is: 83.7
*/
Structure Package
    Public Company As String
    Public Weight As Double
End Structure

Sub SumEx1()
    ' Create a list of Package values.
    Dim packages As New List(Of Package)(New Package() _
     {New Package With {.Company = "Coho Vineyard", .Weight = 25.2},
      New Package With {.Company = "Lucerne Publishing", .Weight = 18.7},
      New Package With {.Company = "Wingtip Toys", .Weight = 6.0},
      New Package With {.Company = "Adventure Works", .Weight = 33.8}})

    ' Sum the values from each item's Weight property.
    Dim totalWeight As Double = packages.Sum(Function(pkg) _
                                             pkg.Weight)

    ' Display the result.
    MsgBox("The total weight of the packages is: " & totalWeight)
End Sub

' This code produces the following output:
'
' The total weight of the packages is: 83.7

설명

이 메서드는 경우 0을 반환 source 요소가 없는.This method returns zero if source contains no elements.

함수를 제공 하는 경우 임의의 값 시퀀스로이 메서드를 적용할 수 있습니다 selector에 프로젝트의 멤버 source 숫자 형식으로 특히 Decimal합니다.You can apply this method to a sequence of arbitrary values if you provide a function, selector, that projects the members of source into a numeric type, specifically Decimal.

Visual Basic 쿼리 식 구문에는 Aggregate Into Sum() 절 뒤에 변환 Sum합니다.In Visual Basic query expression syntax, an Aggregate Into Sum() clause translates to an invocation of Sum.

추가 정보

적용 대상