In this article, you will find some intermediate tools that you can use in your program.
NOTE — The operations (operator overloading, indexers) would work for structs as well. However, the examples would use classes.
If you have ever used List<T> or Dictionary<T> and you were curious about how can an instance of a class can have indices just like an array, then the answer for this is indexers.
In the example below, we can see how to create an indexer.
T — Stands for the value we return from the index.
[int index] — The index the user gave…
Understanding the tricks behind any programming language can make your code to be shorter and more efficient.
In C# OOP we can find some useful tools that can save us a lot of time and place while writing code.
public class SampleClass
{
public int x { get; set; }
public int y { get; set; }
public int z => x + y; //automaticlly holds the sum
}
In the following example, we can see two basic declarations of variables.
The declaration of the x & y variable means that we can get & set their values from anywhere.
…