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

In C# there is the out parameter keyword which causes arguments to be passed by reference. It is like the ref keyword, except that ref requires that the variable be initialized before it is passed. Example:

The out parameter keyword provides a way for a method to output multiple values from a method without […]

dotnet C#

In C# when using the ref keyword it causes an argument to be passed by reference, not by value. In order to use a ref as a parameter, both the method definition and the calling method must explicitly use the ref keyword, and also the variable must be initialized before passing in. In the example […]

dotnet C#

.NET provides in its System.IO namespace the Path class which performs operations on String instances that contain file or directory path information. These operations are performed in a cross-platform manner. Most of the time we see develeopers writing code like

But by using Path.Combine we can provide a cross platform path

By using […]

GhostDoc

Recently have been going through some old code to review the comments in them from other developers and what I find out is developers tend to have really bad comments & documentation in their code Example:

From the above code it is obvious that it is the constructor but does the comment tell me […]

linq

Here is a LINQ tip where you may wish to order a collection with an existing ordering of another collection. Example:

Currently as it stands our data is stored in the order of { 5, 13, 7, 1, 8 } and we wish to order them in terms of { 1, 8, 5, 7, […]

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 […]

UA-4524639-2