Taswar Bhatti
The synonyms of software simplicity
Tag: csharp
dotnet C#

Obsolete or Deprecated? How do you mark a class or method as deprecated/obsolete? By using the Obsolete attribute

dotnet C#

The ?? operator is called the null coalescing operator. It is used for providing a default value for Nullable types or reference types. Example:

One of the disadvantage of ?? is it can create code that is not that readable. e.g a ?? b ?? c ?? d ?? e

dotnet C#

In C# you can have property with different scope (property accessors). Properties in C# can be marked as public, private, protected, internal, or protected internal. Example:

dotnet C#

C# 4.0 allows one to use named and optional parameters. Example:

One can call the method in multiple ways

Additional note, one cannot provide a gap in arguments. Example:

dotnet C#

The using statement in C# is a form of shortcut for try and finally block of code. Things to note is in order to use the using statement the object needs to implement the IDisposable interface, and using does not catch Exception, it just guarantees the call of Dispose. Example:

Can be replaced with […]

interview

In interviews there is always the Singleton question, I personally refuse to answer it on interview. The reason is very simple I don’t code singletons anymore. I use my IoC Container to provide me with a singleton. Sorry if you dont know what an IoC (Inversion of Control Container) is, then you are still in […]

dotnet C#

C# has the as keyword, it is mainly used to cast object of one type to another, and if it fails it should return a null rather than crashing the program or throwing exception. From MSDN documentation it states: You can use the as operator to perform certain types of conversions between compatible reference types […]

dotnet C#

So C# what is the yield keyword? The yield keyword in C# is basically an iterator, its a form of syntactic sugar added from C# 2.0 to create IEnumerable and IEnumerator objects, thus returning one element at a time. From MSDN documentation it states. When you use the yield keyword in a statement, you indicate […]

dotnet C#

In C# if one wishes to use C# constructor overloading they can use the “this” keyword right after to initialize the object, the only thing to note is one will not be able to do any validation of the data using this method. Below I have listed 3 ways that one can initialize constructor overload […]

dotnet C#

C# readonly what is that for? The readonly keyword in C# is used as a modifier. A field can be declared with readonly modifier, and its assignment can only be in the Constructor or when the variable is declared. An example:

The main thing to understand about readonly modifiers is that they are initialized […]

UA-4524639-2