Checklist-To reduce the code and bugs

Less Code=Less Bugs.

The more code you have, the more places there are for bugs to hide. The longer checkouts or compiles take. More time need to be spend on code study.
Ternary Operator
We can avoid complicated “IF ELSE” statements and reduce nesting.Which simplifies the code.So less Work for the compiler

string Signal = "Red";
 if(Signal == "Red")
//Replaced Code
 string answer = Signal == "Red" ? "true" : "false";

Using == or string.equals() for string comparison

String.Equals does offer overloads to handle casing and culture-aware comparison.


Lambda Expreesions in collections

  List<string> list = new List<string>();
//Easier Way to Sort a List
if (this.list.Any(t => t.ToString() == " Two "))

Automatic property in C# 3.5
Normal Way of Writting a property in the olden days.

public class OldExample

   string name
   public string Name
        get { return name;}
        set { name = value; }

With C# 3.0 a new feature called “automatic properties” . Just Type Prop and then press the TAB twice

   public int MyProperty { get; set; }

Compiler does all the job for u.The compiler will automatically generate the backing field at compile time if it finds empty get or set blocks saving you the work. Automatic properties are only for situations where no body is in the get or set blocks.
String is Empty or Not

string.IsNullOrEmpty(String Name)

HappyCoding ! 😉


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: