Unveiled the features of C#
Hello Fellow developers! This article describes some tricks about popular contest questions. 1. Write a program to print current Source code line number in c#: public static void Main(string[] args) { Console.WriteLine("Hello World, from line {0}!", GetLineNumber()); Console.ReadLine(); } private static int GetLineNumber([CallerLineNumber] int sourceLineNumber = 0) { return sourceLineNumber; } You need to use System.Runtime.CompilerServices for "CallerLineNumber" attributes which Allows you to obtain the line number in the source file at which the method is called. Simply easy. isn't it? There are other attributes like [CallerMemberName] - which obtains the method name from which it was called, [CallerFilePath]- returns the source file path. 2. Now next puzzle, is a popular equation "2+2 = 5". so how to do it in C#?. It also pretty simple. believe me! public static void...