M
Markus Freitag
Guest
Hello,
general questions, the procedure.
To understand the existing classes, objects to understand what is possible.
Maybe someone can add helpful examples to extend and demonstrate the features.
Perhaps someone can say something, give concise examples. Thanks in advance for your help.
Best regards Markus
-----------------------
My problem to understand it, what is possible.
public class Progress<T> : IProgress<T>
{
public Progress();
public Progress(Action<T> handler);
public event EventHandler<T> ProgressChanged;
protected virtual void OnReport(T value);
}
I look at the object, what do I have available?
public Progress(Action<T> handler);
//I saw that.
//Action is void, so I can write this.
var progress = new Progress<string>(value => sb.Append($"{value}{Environment.NewLine}"));
or
var progress = new Progress<string>(value =>
{
sb.Append($"{value}{Environment.NewLine}");
Console.WriteLine("Test progress!");
}
);
If I use this, I need not the Eventhandler ProgressChanged, right?
//////////////////////////////////////////////////////
Is that right for my understanding?
Here I define it.
// Action
Action<int> printActionDel = i => Console.WriteLine(i);
printActionDel(10);
// Function
Func<int, int, int> add = Sum;
int result = add(13, 10);
Console.WriteLine(result);
// or
Func<int> getRandomNumber = delegate ()
{
Random rnd = new Random();
return rnd.Next(1, 100);
};
// or
Func<int> getRandomNumber2 = () => new Random().Next(1, 100);
//Or the best
Func<int, int, int> Sum2 = (x, y) => x + y;
Func<int, int, int> Sum3 = (x, y) =>
{
Console.WriteLine($"### {x + y}");
return x + y;
};
// Can I assign a function like this? ##########
//Func<int, int, int> dd = (x, y) => Sum(); #### Can I write similar like this…..??
Console.WriteLine(getRandomNumber2());
Console.WriteLine(Sum2(10, 20));
int erg = Sum3(10, 20);
Action<string> greet = name =>
{
string greeting = $"Hello {name}!";
Console.WriteLine(greeting);
};
greet("World");
Continue reading...
general questions, the procedure.
To understand the existing classes, objects to understand what is possible.
Maybe someone can add helpful examples to extend and demonstrate the features.
Perhaps someone can say something, give concise examples. Thanks in advance for your help.
Best regards Markus
-----------------------
My problem to understand it, what is possible.
public class Progress<T> : IProgress<T>
{
public Progress();
public Progress(Action<T> handler);
public event EventHandler<T> ProgressChanged;
protected virtual void OnReport(T value);
}
I look at the object, what do I have available?
public Progress(Action<T> handler);
//I saw that.
//Action is void, so I can write this.
var progress = new Progress<string>(value => sb.Append($"{value}{Environment.NewLine}"));
or
var progress = new Progress<string>(value =>
{
sb.Append($"{value}{Environment.NewLine}");
Console.WriteLine("Test progress!");
}
);
If I use this, I need not the Eventhandler ProgressChanged, right?
//////////////////////////////////////////////////////
Is that right for my understanding?
Here I define it.
// Action
Action<int> printActionDel = i => Console.WriteLine(i);
printActionDel(10);
// Function
Func<int, int, int> add = Sum;
int result = add(13, 10);
Console.WriteLine(result);
// or
Func<int> getRandomNumber = delegate ()
{
Random rnd = new Random();
return rnd.Next(1, 100);
};
// or
Func<int> getRandomNumber2 = () => new Random().Next(1, 100);
//Or the best
Func<int, int, int> Sum2 = (x, y) => x + y;
Func<int, int, int> Sum3 = (x, y) =>
{
Console.WriteLine($"### {x + y}");
return x + y;
};
// Can I assign a function like this? ##########
//Func<int, int, int> dd = (x, y) => Sum(); #### Can I write similar like this…..??
Console.WriteLine(getRandomNumber2());
Console.WriteLine(Sum2(10, 20));
int erg = Sum3(10, 20);
Action<string> greet = name =>
{
string greeting = $"Hello {name}!";
Console.WriteLine(greeting);
};
greet("World");
Continue reading...