C# 1001 notes
6.51K subscribers
329 photos
9 videos
2 files
313 links
Регулярные короткие заметки по C# и .NET.

Просто о сложном для каждого.

admin - @haarrp
加入频道
Here is a solution for the #challenge above
C# 1001 notes
Here is a solution for the #challenge above
💬 Actually, I vote for this solution to this #challenge instead.

Thx to Roman!
Have a great weekend and perfect first code 😉
📝 What is the difference between continue and break statements in C#?

🔸 using break statement, you can jump out of a loop

🔸 using continue statement, you can jump over one iteration and then resume your loop execution

#post
📝 When to use Finalize vs Dispose?

🔸 The finalizer method is called when your object is garbage collected and you have no guarantee when this will happen (you can force it, but it will hurt performance).

🔸 The Dispose method, on the other hand, is meant to be called by the code that created your class so that you can clean up and release any resources you have acquired (unmanaged data, database connections, file handles, etc) the moment the code is done with your object.

The standard practice is to implement IDisposable and Dispose so that you can use your object in a using statement such as using(var foo = new MyObject()) { }.

And in your finalizer, you call Dispose, just in case the calling code forgot to dispose of you.

#post
#challenge

💻 Perfect Number | #easy

Create a function that tests whether or not an integer is a perfect number. A perfect number is a number that can be written as the sum of its factors, (equal to sum of its proper divisors) excluding the number itself.

For example, 6 is a perfect number, since 1 + 2 + 3 = 6, where 1, 2, and 3 are all factors of 6. Similarly, 28 is a perfect number, since 1 + 2 + 4 + 7 + 14 = 28.

Examples:

CheckPerfect(6) ➞ true
CheckPerfect(28) ➞ true
CheckPerfect(496) ➞ true
CheckPerfect(12) ➞ false
CheckPerfect(97) ➞ false

🏆 Leave your solutions in the comments. The solution will be posted below in a couple of hours 👇

#interview
Here is a solution for the #challenge above
📝 What are Property Accessors?

The get and set portions or blocks of a property are called accessors.

These are useful to restrict the accessibility of a property.

🔸 The set accessor specifies that we can assign a value to a private field in a property and without the set accessor property it is like a read-only field.

🔸 By the get accessor we can access the value of the private field. A Get accessor specifies that we can access the value of a field publicly.

#post
What will be the output of the following code snippet?
Anonymous Quiz
47%
40, 25000, 50000
6%
40, 25000, 25000
11%
40, 50000, 50000
36%
Error
📝 You have defined a destructor but it never executed. Why?

The runtime environment automatically invokes the destructor of a class to release the resources that are occupied by variables and methods of an object.

However, in C#, programmers cannot control the timing for invoking destructors, as Garbage Collector is only responsible for releasing the resources used by an object.

Garbage Collector automatically gets information about unreferenced objects from .NET's runtime environment and then invokes the Finalize() method.

Although, it is not preferable to force Garbage Collector to perform garbage collection and retrieve all inaccessible memory (programmers can use the Collect() method of the Garbage Collector class to forcefully execute Garbage Collector).

Take notice that the destructor doesn't (and can't) have a public modifier in-front of it, it's sort of an hint that you can't explicitly call the destructor of an object.

#post
#challenge

💻 Is the Input Factorial of an Integer? | #easy

Create a function that checks if a given integer is exactly the factorial of an integer or not. true if it is, false otherwise.

Examples:

isFactorial(2) ➞ true
// 2 = 2 * 1 = 2!

isFactorial(27) ➞ false

isFactorial(24) ➞ true
// 24 = 4 * 3 * 2 * 1 = 4!

🏆 Leave your solutions in the comments. The solution will be posted below in a couple of hours 👇

#interview
Here is a solution for the #challenge above
📝 What is the difference between a Struct and a Class in C#?

Class and struct both are the user defined data type but have some major difference:

Struct

🔸 The struct is value type in C# and it inherits from System.Value Type.

🔸 Struct is usually used for smaller amounts of data.

🔸 Struct can't be inherited to other type.

🔸 A structure can't be abstract.

Class

🔸 The class is reference type in C# and it inherits from the System.Object Type.

🔸 Classes are usually used for large amounts of data.

🔸 Classes can be inherited to other class.

🔸 A class can be abstract type.

🔸 We can create a default constructor.

#post
What will be the output of the following code snippet?
Anonymous Quiz
84%
8
1%
0
11%
2
4%
16