moon
moon
CC#
Created by moon on 9/9/2023 in #help
❔ Action and Callback
Action<Action<int, string, bool>> configureDisplayInfo = (callback) =>
{
int age = 30;
string name = "Alice";
bool isActive = true;

callback(age, name, isActive);
};

Action<int, string, bool> displayInfo = (age, name, isActive) =>
{
Console.WriteLine($"Name: {name}");
Console.WriteLine($"Age: {age}");
Console.WriteLine($"Is Active: {isActive}");
};

configureDisplayInfo(displayInfo);
Action<Action<int, string, bool>> configureDisplayInfo = (callback) =>
{
int age = 30;
string name = "Alice";
bool isActive = true;

callback(age, name, isActive);
};

Action<int, string, bool> displayInfo = (age, name, isActive) =>
{
Console.WriteLine($"Name: {name}");
Console.WriteLine($"Age: {age}");
Console.WriteLine($"Is Active: {isActive}");
};

configureDisplayInfo(displayInfo);
We are passing a function named "callback" as if it were a variable as a parameter, and then we are calling it as if we had previously called the function by saying "callback(age, ...)". How does this process work, how do the codes work step by step?
11 replies
CC#
Created by moon on 9/8/2023 in #help
❔ builder.Services.AddDbContext<>
builder.Services.AddDbContext<UygulamaDbContext>( options => options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));
builder.Services.AddDbContext<UygulamaDbContext>( options => options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));
The 'options' here, where did it exactly come from, and we were also able to access it by putting a dot (options.)? Is it something like the callback in JavaScript?
7 replies