Check If IEnumerable<> or List<> Type is Empty / Null

There are three ways to check whether IEnumerable<> or List<> type is empty / null or not. == NULL .Any() .Count() In any case, you always want to combine “== null” and, either “.Any()” or “.Count()”, with OR (“||”) operator. In addition, you want to put “== null” before the other condition. The reason for this is, “if” condition goes from left to right. So, if the list object is null, it will not go to the second check,…

Read More

Foreach C#

A program iterates over a collection. The index of each element is not needed. Only the elements are needed. With foreach we access just the elements. A foreach-loop, this is the easiest, least error-prone loop. It is preferred in many program contexts. Here are some samples: using System; class Program { static void Main() { string[] pets = { “dog”, “cat”, “bird” }; // … Loop with the foreach keyword. foreach (string value in pets) { Console.WriteLine(value); } }…

Read More

Visual Studio 2015 keyboard shortcuts – The complete list

Analyze Navigate Backward Shift+Alt+3 Navigate Forward Shift+Alt+4 Architecture New Code Map Ctrl+\, Ctrl+O New UMLor Layer Diagram Ctrl+\, Ctrl+N Architecture Context Menus Add Node Ins Both Dependencies B Incoming Dependencies I Outgoing Dependencies O New Comment Ctrl+Shift+K Ctrl+E, C Remove Del Rename F2 Build Build Solution Ctrl+Shift+B Cancel Ctrl+Break Compile Ctrl+F7 Run Code Analysison Solution Alt+F11 Class Diagram Collapse Num – Expand Num + Class View Context Menus Properties Alt+Enter Misc Commit All Edits Shift+Alt+U Move Left Edgetotheleft Ctrl+Shift+,…

Read More

LINQ
 to 
SQL 
in 
C# – Cheat Sheet

LINQ
 to 
SQL
 in
 C# – Cheat
 Sheet Database context & database create var db = new MyDataContext(@”server=.\SQLEXPRESS;database=my;integrated security=SSPI”); if (!db.DatabaseExists()) db.CreateDatabase(); Select one Insert var only = db.Customers.SingleOrDefault(c => c.CustID == “CHIPS”); var first = db.Customers.FirstOrDefault(c => c.CustID == “CHIPS”); var customer = new Customer() { CustID = “CHIPS”, CompanyName = “Mr. Chips” }; db.Customers.InsertOnSubmit(customer); db.SubmitChanges();   – –  – – – – – – – – – – – – – – – – – – –…

Read More

Built-in C# Data Types

C# is a strongly-typed language. Before a value can be stored in a variable, the type of the variable must be specified, as in the following examples: int a = 1; string s = “Hello”; XmlDocument tempDocument = new XmlDocument();   Note that the type must be specified both for simple, built-in types such as an int, and for complex or custom types such as XmlDocument.   C# includes support for the following built-in data types: Data Type Range byte 0…

Read More