Получи случайную криптовалюту за регистрацию!

C# 1001 notes

Логотип телеграм канала @csharp_1001_notes — C# 1001 notes C
Логотип телеграм канала @csharp_1001_notes — C# 1001 notes
Адрес канала: @csharp_1001_notes
Категории: Технологии
Язык: Русский
Количество подписчиков: 2.63K
Описание канала:

Регулярные короткие заметки по C# и .NET.
Просто о сложном для каждого.
admin - @notxxx1

Рейтинги и Отзывы

3.50

2 отзыва

Оценить канал csharp_1001_notes и оставить отзыв — могут только зарегестрированные пользователи. Все отзывы проходят модерацию.

5 звезд

1

4 звезд

0

3 звезд

0

2 звезд

1

1 звезд

0


Последние сообщения

2022-06-23 13:01:19 ​​Difference between static, readonly, and constant in C# (part 4)

The following example demonstrates the difference between static, readonly, and const variables.

Like this note? Want to support the channel? Become a patron: https://www.patreon.com/csharp1001notes
166 views10:01
Открыть/Комментировать
2022-06-22 13:00:27 Difference between static, readonly, and constant in C# (part 3)

const:

Declared using the const keyword. By default a const is static that cannot be changed.

Only the class level fields or variables can be constant.

The constant fields must be initialized at the time of declaration. Therefore, const variables are used for compile-time constants.

Constant variables cannot be modified after declaration.

Const members can be accessed using ClassName.ConstVariableName, but cannot be accessed using object.
289 views10:00
Открыть/Комментировать
2022-06-21 13:01:33 Difference between static, readonly, and constant in C# (part 2)

readonly:

Declared using the readonly keyword.

Only the class level fields can be readonly. The local variables of methods cannot be readonly.

Readonly fields can be initialized at declaration or in the constructor. Therefore, readonly variables are used for the run-time constants.

Readonly variable cannot be modified at run-time. It can only be initialized or changed in the constructor.

Readonly members can be accessed using object, but not ClassName.ReadOnlyVariableName.
75 views10:01
Открыть/Комментировать
2022-06-20 13:01:00 Difference between static, readonly, and constant in C# (part 1)

static:

Declared using the static keyword.

Classes, constructors, methods, variables, properties, event and operators can be static. The struct, indexers, enum, destructors, or finalizers cannot be static.

Static members can only be accessed within the static methods. The non-static methods cannot access static members.

Value of the static members can be modified using ClassName.StaticMemberName.

Static members can be accessed using ClassName.StaticMemberName, but cannot be accessed using object.
283 views10:01
Открыть/Комментировать
2022-06-16 13:01:08 ​​async, await, and Task (part 4)

If you have multiple async methods that return the values then you can use await for all methods just before you want to use the return value in further steps.

In the above program, we do await result1 and await result2 just before we need to pass the return value to another method.

Thus, you can use async, await, and Task to implement asynchronous programming in .NET Framework or .NET Core using C#.

The channel has been running since 2018. It needs your support: https://www.patreon.com/csharp1001notes
232 views10:01
Открыть/Комментировать
2022-06-15 13:03:36 ​​async, await, and Task (part 3)

Use async along with await and Task if the async method returns a value back to the calling code. We used only the async keyword in the above program to demonstrate the simple asynchronous void method.

The await keyword waits for the async method until it returns a value. So the main application thread stops there until it receives a return value.

The Task class represents an asynchronous operation and Task generic class represents an operation that can return a value. In the above example, we used await Task.Delay(4000) that started async operation that sleeps for 4 seconds and await holds a thread until 4 seconds.

The following demonstrates the async method that returns a value.

In the above example, in the static async Task LongProcess() method, Task is used to indicate the return value type int. int val = await result; will stop the main thread there until it gets the return value populated in the result. Once get the value in the result variable, it then automatically assigns an integer to val.

An async method should return void, Task, or Task, where TResult is the return type of the async method. Returning void is normally used for event handlers. The async keyword allows us to use the await keyword within the method so that we can wait for the asynchronous method to complete for other methods which are dependent on the return value.
277 views10:03
Открыть/Комментировать
2022-06-14 13:01:02 ​​What is Asynchronous Programming? (part 2)

In asynchronous programming, the code gets executed in a thread without having to wait for an I/O-bound or long-running task to finish. For example, in the asynchronous programming model, the LongProcess() method will be executed in a separate thread from the thread pool, and the main application thread will continue to execute the next statement.

Microsoft recommends Task-based Asynchronous Pattern  to implement asynchronous programming in the .NET Framework or .NET Core applications using async , await keywords and Task or Task class.

Now let's rewrite the above example in asynchronous pattern using async keyword.

In the above example, the Main() method is marked by the async keyword, and the return type is Task. The async keyword marks the method as asynchronous. Note that all the methods in the method chain must be async in order to implement asynchronous programming. So, the Main() method must be async to make child methods asynchronous.

The LongProcess() method is also marked with the async keyword which makes it asynchronous. The await Task.Delay(4000); holds the thread execute for 4 seconds.

Now, the program starts executing from the async Main() method in the main application thread. The async LongProcess() method gets executed in a separate thread and the main application thread continues execution of the next statement which calls ShortProcess() method and does not wait for the LongProcess() to complete.
223 views10:01
Открыть/Комментировать
2022-06-13 13:01:39 ​​Asynchronous programming with async, await, Task in C# (part 1)

C# and .NET Framework (4.5 & Core) supports asynchronous programming using some native functions, classes, and reserved keywords.

Before we see what is asynchronous programming, let's understand what is synchronous programming using the following console example.

In the above example, the LongProcess() method is some long-running task such as reading a file from the server, calling a web API that returns a large amount of data or uploading or downloading a big file. It takes a little longer time to execute (Thread.Sleep(4000) holds it for 4 seconds just to show long execution time). The ShortProcess() is a simple method that gets executed after the LongProcess() method.

The above program executes synchronously. It means execution starts from the Main() method wherein it first executes the LongProcess() method and then ShortProcess() method. During the execution, an application gets blocked and becomes unresponsive (You can see this in Windows-based applications mainly). This is called synchronous programming where execution does not go to next line until the current line executed completely.
228 views10:01
Открыть/Комментировать
2022-06-08 17:35:00
In C#, what is similar to C++ function pointer?
Anonymous Quiz
6%
Event
5%
Interface
79%
Delegate
10%
Method
153 voters292 views14:35
Открыть/Комментировать
2022-06-01 17:35:00
Which of the followings does not allow you to use C# static keyword?
Anonymous Quiz
1%
(Method) static void Run() {}
11%
(Property) static int Prop {get; set;}
7%
(Field) static int _field;
1%
(Class) static class MyClass {}
11%
(Constructor) static MyClass() {}
47%
(Destructor) static ~MyClass() {}
22%
(Event) static event EventHandler evt;
73 voters185 views14:35
Открыть/Комментировать