From 3c3797168280f27b3ef91ce59a00e7a8c0fe9b0f Mon Sep 17 00:00:00 2001 From: omid ahmadpour Date: Sun, 14 Aug 2022 11:36:21 +0200 Subject: [PATCH] Update README.md add one guidline regarding best practice for returning null collection. --- README.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/README.md b/README.md index 4e202b5..642b964 100644 --- a/README.md +++ b/README.md @@ -762,3 +762,31 @@ bool RequestIsValid(int id) ``` Visual Studio shortcut : CRTL+R+G ``` + +### Don't return null collection in your code: + +``` +public IEnumerable GetUsers() +{ + if (SomeConditions()) + { + return null; + } + + return Data; +} +``` + +👍 Do use Enumerable.Empty instead: + +``` +public IEnumerable GetUsers() +{ + if (SomeConditions()) + { + return Enumerable.Empty(); + } + + return Data; +} +```