C
C#2y ago
SWEETPONY

❔ what is difference between _ and ()?

I have following in constuctor:
var initialize = ReactiveCommand.CreateFromTask( async () =>
{
const string databaseFileName = "log.db";
var databaseFilePath = Path.Combine( Path.GetTempPath(), databaseFileName );
var database = new SQLiteAsyncConnection(databaseFilePath);

await database.CreateTableAsync<MqttDelivery>();
} );
initialize.Subscribe();
initialize.Execute();

var initialize = ReactiveCommand.CreateFromTask( async _ =>
{
const string databaseFileName = "log.db";
var databaseFilePath = Path.Combine( Path.GetTempPath(), databaseFileName );
var database = new SQLiteAsyncConnection(databaseFilePath);

await database.CreateTableAsync<MqttDelivery>();
} );
initialize.Subscribe();
initialize.Execute();
var initialize = ReactiveCommand.CreateFromTask( async () =>
{
const string databaseFileName = "log.db";
var databaseFilePath = Path.Combine( Path.GetTempPath(), databaseFileName );
var database = new SQLiteAsyncConnection(databaseFilePath);

await database.CreateTableAsync<MqttDelivery>();
} );
initialize.Subscribe();
initialize.Execute();

var initialize = ReactiveCommand.CreateFromTask( async _ =>
{
const string databaseFileName = "log.db";
var databaseFilePath = Path.Combine( Path.GetTempPath(), databaseFileName );
var database = new SQLiteAsyncConnection(databaseFilePath);

await database.CreateTableAsync<MqttDelivery>();
} );
initialize.Subscribe();
initialize.Execute();
the first one will be executed second one will be skipped why?
5 Replies
SWEETPONY
SWEETPONYOP2y ago
hm, second one will be called if I call command again interesting! It doesn't run in constructor but it can be runned directly ah okay! thanks
Angius
Angius2y ago
_ is a discard So () => foo is a parameterless lambda While _ => foo is a lambda with one parameter, but you don't need it so you discard it Similarly, (_, _) => foo is a lambda with two params, both discarded Etc
SWEETPONY
SWEETPONYOP2y ago
thats why task wouldn't be executed in constructor?
Angius
Angius2y ago
Seeing how the version with a parameter is supposed to get a cancellation token, and it gets discarded instead... possibly
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server