42
1
using System;
2
using System.Runtime.CompilerServices;
3
using System.Collections.Generic;
4
using System.Linq;
5
6
public class Program
7
{
8
static List<Person> persons = new List<Person>() {
9
new Person(1, "Person1", "Chennai"),
10
new Person(2, "Person2", "Mumbai"),
11
new Person(3, "Person3", "Delhi"),
12
};
13
14
public static void Main()
15
{
16
var a = 5;
17
CheckExpression(a > 5);
18
19
FilterPersons(p => p.City == "Bangalore");
20
}
21
22
static void CheckExpression(bool condition, [CallerArgumentExpression("condition")] string message = null)
23
{
24
if(condition) {
25
Console.WriteLine("continue success");
26
}
27
else
28
{
29
Console.WriteLine($"Condition failed - {message}");
30
}
31
}
32
33
static List<Person> FilterPersons(Func<Person, bool> condition, [CallerArgumentExpression("condition")] string message = null) {
34
var result = persons.Where(condition);
35
if(result.Count() == 0) {
36
Console.WriteLine($"filter 0 records - {message}");
37
}
38
return result.ToList();
39
}
40
}
41
42
public record Person(int Id, string FirstName, string City);
Cached Result