In C#, lambda can access local variable, and also return some data.
then, which is better in following situation?
int num;
Func<int> func = ()=>{return 10;}
num = func();
vs
int num;
Action action = ()=>{num = 10;}
I think, the performance is different.
Which is better?
UPDATE(I dont know how to use StackOverflow)
My code here.
ErrorCode errorCode;
errorCode = DatabaseUtility.Read<ErrorCode>(
conn,
DatabaseUtility.CreateSelectQuery(....),
reader =>
{
if(reader.Read())
return ErrorCode.None;
return ErrorCode.InvalidParam;
});
But in this case, may be I can do like this.
ErrorCode errorCode;
DatabaseUtility.Read(
conn,
DatabaseUtility.CreateSelectQuery(....),
reader =>
{
if(reader.Read())
errorCode = ErrorCode.None;
else
errorCode = ErrorCode.InvalidParam;
});
And, this is the method definition.
public static class DatabaseUtility
{
public static Read<T>(
MySqlConnection conn,
string query,
Func<MySqlDataReader, T> callback);
}
10tonumdirectly?