Avatar ·

Why use Expression<Func<T>> instead of Func<T> in C#? Difference with examples

Hello colleagues. I started learning C# and came across something like Expression>. It seems that both Func and Expression> look the same when I write lambdas. But why is this "Expression" needed? \n\nHere's a simple example. I have a method that takes Func:\n\n```csharp\npublic void Filter(Func predicate) {\n var numbers = new List {1, 2, 3, 4, 5};\n var result = numbers.Where(predicate).ToList();\n // do something with result\n}\n```\n\nI call it like this: `Filter(x => x > 3);` — it works.\n\nBut I've seen that in Entity Framework they often use Expression>. For example:\n\n```csharp\npublic IQueryable GetData(Expression> predicate) {\n return dbSet.Where(predicate);\n}\n```\n\nWhat is the fundamental difference?