How to get the average of a list that contains null value?

Alick Wang 266 Reputation points
2023-03-29T00:51:53.2266667+00:00

How to get the average of a list that contains null value?

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,843 questions
{count} votes

Accepted answer
  1. Karen Payne MVP 35,401 Reputation points
    2023-03-29T01:14:32.8833333+00:00

    Seems you need a nullable list which in this case returns 10.75

    List<int?> list = new List<int?>() {10,null,11,12,10};
    Console.WriteLine(list.Average());
    
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.