🔧 Action vs. Function in C# – What's the Difference?
Nachrichtenbereich: 🔧 Programmierung
🔗 Quelle: dev.to
In C#, both Action and Function (Func<>) are delegates, but they serve different purposes.
🔹 Action ➡ Represents a method that does not return a value (void).
Action printMessage = message => Console.WriteLine(message);
printMessage("Hello, LinkedIn!");
Here, printMessage takes a string as input and prints it but doesn’t return anything.
🔹 Func ➡ Represents a method that returns a value.
Func add = (a, b) => a + b;
int sum = add(5, 10);
Console.WriteLine(sum); // Output: 15
Here, add takes two integers and returns their sum.
Key Takeaway: Use Action when you don’t need a return value and Func when you do!
...
🔧 Grok 3: AI Thông Minh Nhất Thế Giới
📈 28.6 Punkte
🔧 Programmierung
🔧 Có thể bạn chưa biết (Phần 1)
📈 28.6 Punkte
🔧 Programmierung
📰 Difference-in-Difference 101
📈 19.66 Punkte
🔧 AI Nachrichten
🔧 DAY-8 PSQL, Difference Function vs. Procedure
📈 18.55 Punkte
🔧 Programmierung
🔧 為什麼 member function 不叫做 function member?
📈 17.44 Punkte
🔧 Programmierung