UnionUnion combines multiple collections into a single collection and returns a resultant collection with unique elementsIntersectIntersect returns sequence elements which are common in both the input sequencesExceptExcept returns sequence elements from the first input sequence that are not present in the second input sequenceExampleclass Program{ static void Main(){ int[] count1 = { 1, 2, 3, 4 }; int[] count2 = { 2, 4, 7 }; var resultUnion = count1.Union(count2); var resultIntersect = count1.Intersect(count2); var resultExcept = count1.Except(count2); System.Console.WriteLine("Union"); ... Read More
Build solutionThis will perform an incremental build. In other words it will only build code files which have changed.If they have not changed those files will not be touched. Compiles code files (DLL and EXE) which are changed.Rebuild solutionThis will delete all currently compiled files (i.e., exe and DLLs) and will build everything from scratch,Irrespective of if there is code change in the file or not.Clean solutionThis menu will delete all compiled files (i.e., EXE’s and DLL’s) from the bin/obj directory.Rebuild = Clean + Build
Make use of this keyword in c# to call one constructor from another constructor To call a constructor which is present in parent class make use of base keywordExampleTo call a constructor which is present in another class make use of base keywordclass DemoBase{ public DemoBase(int firstNumber, int secondNumber, int thirdNumber){ System.Console.WriteLine("Base class Constructor"); System.Console.WriteLine($"{firstNumber} {secondNumber} {thirdNumber}"); } } class Demo : DemoBase{ public Demo(int firstNumber, int secondNumber, int thirdNumber) : base(firstNumber, secondNumber, thirdNumber){ System.Console.WriteLine("Derived class Constructor"); System.Console.WriteLine($"{firstNumber} {secondNumber} {thirdNumber}"); } } class Program{ ... Read More
In c#, Destructor is a special method of a class and it is used inside a class to destroy the object or instances of classes.There can be only one destructor inside a classFollowing are the properties of destructor in c#Destructors will not take any parametersDestructors will begin with a tilde symbol(~)Destructors (~) cannot be defined in Structs.Destructor cannot be called. They are invoked automatically.Destructor implicitly calls Finalize on the base class of object.Exampleclass Demo{ ~Demo(){ //Finalizer // cleanup statements... } } class Program{ static void Main(){ Console.ReadLine(); } }The finalizer ... Read More
Select operator produces one result value for every source SelectMany Operator belong to Projection Operators category. It is used to project each element of a sequence to an IEnumerable and flattens the resulting sequences into one sequence.Exampleclass Demo{ public string Name { get; set; } public List Contents { get; set; } public static ListGetAllContents(){ List listContents = new List{ new Demo{ Name = "Cap", Contents = new List { "Nike", "Adidas" } }, ... Read More
Here in the example a static Demo class is created and a static variable count is declared.Here the count variable is treated as a global variable .so it keeps on increasing in the example ,because only one instance of the class is createdExamplestatic class Demo{ public static int count; static Demo(){ System.Console.WriteLine("Static Constuctor called"); } } class Program{ static void Main(){ Demo.count++; Demo.count++; System.Console.WriteLine(Demo.count); Console.ReadKey(); } }OutputStatic Constuctor called 2
Make use of this keyword in c# to call one constructor from another constructorTo call a constructor which is present in parent class make use of base keywordExampleclass Demo{ public Demo(){ System.Console.WriteLine("Parameter less constructor called"); } public Demo(int firstNumber, int secondNumber) : this(){ System.Console.WriteLine($"{firstNumber} {secondNumber}"); } public Demo(int firstNumber, int secondNumber, int thirdNumber) : this(firstNumber, secondNumber){ System.Console.WriteLine($"{firstNumber} {secondNumber} {thirdNumber}"); } } class Program{ static void Main(){ Demo obj = new Demo(1, 2, 3); Console.ReadLine(); } }OutputParameter less ... Read More
Static constructor are called automatically before the first instance is created or any static members are referenced.A static constructor is used to initialize any static data, or to perform a particular action that needs to be performed once only.In c#, only one static constructor is allowed to createStatic constructors have the following properties −A static constructor does not take access modifiers or have parameters.A class or struct can only have one static constructor.Static constructors cannot be inherited or overloaded.A static constructor cannot be called directly and is only meant to be called by the common language runtime (CLR). It is ... Read More
In C# 5.0 and before to give an value to the Auto Property we have to do in the constructorThe constructor will be automatically called when class is instantiated and the value will be setAfter C#5.0 a new way to give a value to auto property has come which is similar in assigning a value to the variableExampleSet Value in Constructor class Demo{ public Demo(){ FirstName = "DemoName"; } public string FirstName { get; set; } } class Program{ static void Main(){ Demo obj = new Demo(); ... Read More
In c# multiple values can be returned using the below approaches −Reference parametersOutput parametersReturning an ArrayReturning a TupleReference parametersExampleclass Program{ static int ReturnMultipleValuesUsingRef(int firstNumber, ref int secondNumber){ secondNumber = 20; return firstNumber; } static void Main(){ int a = 10; int refValue = 0; var res = ReturnMultipleValuesUsingRef(a, ref refValue); System.Console.WriteLine($" Ref Value {refValue}"); System.Console.WriteLine($" Function Return Value {res}"); Console.ReadLine(); } }OutputRef Value 20 Function Return Value 10Output parametersExampleclass Program{ static ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP