Pattern matching example

Code × Dismiss alert dashedLine(“50”); newDashed(“100”); Console.WriteLine(isIdesOfMarch(new DateTime(DateTime.Today.Year, 1, 13))); Console.WriteLine(isIdesOfMarch(new DateTime(DateTime.Today.Year, 3, 15))); Console.WriteLine(isIdesOfMarch(new DateTime(DateTime.Today.Year, 3, 17))); //is expression…to test the constant pattern //is expression also used to with whats called declaration pattern string? str = null; if (str is not null) Console.WriteLine(“not null”); else Console.WriteLine(“null”); //declaration pattern void newDashed(object o) { //”50″..l=50 //50…l=50 … Read more

Generic Collection Best Practices-1

Code × Dismiss alert var result = GetProducts();//list var result1 = GetProductsArray();//array var result2 = GetProductsDict();//dict //list and array –> ILIST… //dic –> Idiction.. //Ilist and Idic –> Icollection Display(result); Display(result1); Display(result2.Values); Console.WriteLine(“test”); bool result12 = false; System.Console.WriteLine(bool.TryParse(“Off”, out result12)); static void Display(ICollection products) { foreach (var item in products) { Console.WriteLine(item.Price); } } /*IList…IDictionary,,Icollection….IEnumerable…. … Read more

Tuple

Code × Dismiss alert /* Tuple class -> C# 4.0 * Value Tuple, deconstruction and discards from c# 7.0 */ //Tuple Class //1.Useful to return multiple values from a method or to pass multiple values to a method. //2.Represents a set of values….no class //3.Tuple stores only a set of values(of any data type..); but … Read more