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

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


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

2022-01-03 12:30:00
What is enum in C#?

An enum is a value type with a set of related named constants often referred to as an enumerator list. The enum keyword is used to declare an enumeration. It is a primitive data type, which is user defined. An enum is used to create numeric constants in .NET framework. All the members of enum are of enum type. Their must be a numeric value for each enum type.

Some points about enum:

Enums are enumerated data type in C#.

Enums are strongly typed constant. They are strongly typed, i.e. an enum of one type may not be implicitly assigned to an enum of another type even though the underlying value of their members are the same.

Enumerations (enums) make your code much more readable and understandable.

Enum values are fixed. Enum can be displayed as a string and processed as an integer.

The default type is int, and the approved types are byte, sbyte, short, ushort, uint, long, and ulong.

Enums are value types and are created on the stack and not on the heap.
330 views09:30
Открыть/Комментировать
2021-12-30 12:30:05
What is a preprocessor directives in C#?

The preprocessor directives give instruction to the compiler to preprocess the information before actual compilation starts. Generally, the optional/conditional compilation symbols will be provided by the build script.

Not only is this cleaner and easier to read since you don't end up having #if, #else within your code. This style is less prone to errors either during normal code edits and well as logic flow errors.
234 views09:30
Открыть/Комментировать
2021-12-28 18:20:00
What will be the output of the following code snippet?
Anonymous Quiz
55%
Class Executed, Interface Executed
38%
Class Executed
6%
Interface Executed
1%
NullReferenceException
80 voters261 views15:20
Открыть/Комментировать
2021-12-28 18:20:00
263 views15:20
Открыть/Комментировать
2021-12-27 12:30:00
Can this be used within a Static method?

We can't use this in static method because keyword this returns a reference to the current instance of the class containing it.

Static methods (or any static member) do not belong to a particular instance. They exist without creating an instance of the class and call with the name of a class not by instance so we can't use this keyword in the body of static Methods, but in case of Extension Methods we can use it as the functions parameters.
180 views09:30
Открыть/Комментировать
2021-12-23 12:30:00
What is the use of static constructors?

A static constructor is useful for initializing any static fields associated with a type (or any other per-type operations) - useful in particular for reading required configuration data into readonly fields, etc.

It is run automatically by the runtime the first time it is needed (the exact rules there are complicated (see "beforefieldinit"), and changed subtly between CLR2 and CLR4). Unless you abuse reflection, it is guaranteed to run at most once (even if two threads arrive at the same time).

You can't overload it.
364 views09:30
Открыть/Комментировать
2021-12-21 18:20:00
What will be the output of the following code snippet?
Anonymous Quiz
49%
Welcome Readers, To the World of C# !!
42%
Welcome Readers
4%
ThreadAbortException
5%
Program compiles successfully and nothing is printed
147 voters415 views15:20
Открыть/Комментировать
2021-12-21 18:20:00
407 views15:20
Открыть/Комментировать
2021-12-20 12:30:01
What is Managed or Unmanaged Code?

Managed Code - The code, which is developed in .NET framework is known as managed code. This code is directly executed by CLR with the help of managed code execution. Any language that is written in .NET Framework is managed code.

Unmanaged Code - The code, which is developed outside .NET framework is known as unmanaged code. Applications that do not run under the control of the CLR are said to be unmanaged, and certain languages such as C++ can be used to write such applications, which, for example, access low - level functions of the operating system. Background compatibility with the code of VB, ASP and COM are examples of unmanaged code.
124 views09:30
Открыть/Комментировать
2021-12-16 12:30:01
What is the volatile keyword used for?

In C# volatile tells the compiler that the value of a variable must never be cached as its value may change outside of the scope of the program itself (such as the operating system, the hardware, or a concurrently executing thread). The compiler will then avoid any optimisations that may result in problems if the variable changes "outside of its control".

Or in more simple terms:

Sometimes, the compiler will optimize a field and use a register to store it. If thread 1 does a write to the field and another thread accesses it, since the update was stored in a register (and not memory), the 2nd thread would get stale data.

You can think of the volatile keyword as saying to the compiler "I want you to store this value in memory". This guarantees that the 2nd thread retrieves the latest value.
187 views09:30
Открыть/Комментировать