Skip to content

Instantly share code, notes, and snippets.

@ankitvijay
ankitvijay / Program.cs
Last active January 13, 2018 23:01
Non Short Circuit Example 1
using System;
namespace ShortCircuitExample
{
public class Program
{
static void Main(string[] args)
{
if (IsStoreOpen() && NeedGrocery())
{
@ankitvijay
ankitvijay / Program.cs
Created January 13, 2018 23:14
Non Short Circuit Example 2
using System;
namespace NonShortCircuitExample
{
public class Program
{
static void Main(string[] args)
{
if (IsStoreOpen() & NeedGrocery())
{
@ankitvijay
ankitvijay / IdValidationHelper.cs
Last active January 13, 2018 23:38
Static Using Example 3
namespace staticUsingExample
{
public static class IdValidationHelper
{
public static bool IsValid(string id)
{
bool isValid = false;
// Validate id
@ankitvijay
ankitvijay / FastFailExample
Last active January 21, 2018 03:19
Fast Fail Example
using System;
namespace FastFailExample
{
public class Program
{
static void Main(string[] args)
{
try
{
@ankitvijay
ankitvijay / System
Last active January 21, 2018 06:22
Global Namespace Example1
namespace GlobalNamespaceAliasExample
{
public class System
{
public void Log(string message)
{
// Code to log
}
}
}
@ankitvijay
ankitvijay / System.cs
Created January 21, 2018 06:23
Global Namespace Example2
namespace GlobalNameSpaceAliasExample
{
public class System
{
public void Log(string message)
{
global::System.Console.WriteLine(message);
}
}
}
@ankitvijay
ankitvijay / NumberStylesExample
Last active January 21, 2018 07:09
Number Styles Example
using System;
using System.Globalization;
namespace NumberStylesExample
{
public class Program
{
static void Main(string[] args)
{
// A Hexadecimal number with trailing and leading white spaces
@ankitvijay
ankitvijay / Program.cs
Created January 21, 2018 11:41
Extern alias example 3
extern alias assembly1;
namespace NamespaceAliasExample
{
public class Program
{
static void Main(string[] args)
{
assembly1::SameNamespaceName.Class1.MethodA();
SameNamespaceName.Class2.MethodB();
@ankitvijay
ankitvijay / Assembly2: SameNamespaceName.Class2
Last active January 21, 2018 11:42
Extern alias example 2
using System;
namespace SameNamespaceName
{
public class Class2
{
public static void MethodB()
{
var assemblyame = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
Console.WriteLine($"Assemble Name: {assemblyame}");
@ankitvijay
ankitvijay / Assembly1: SameNamespaceName.Class1
Last active January 21, 2018 11:43
Extern alias example 1
using System;
namespace SameNamespaceName
{
public class Class1
{
public static void MethodA()
{
var assemblyame = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
Console.WriteLine($"Assemble Name: {assemblyame}");