Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Programming Articles - Page 1825 of 3363
4K+ Views
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
229 Views
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
1K+ Views
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
849 Views
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
2K+ Views
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
3K+ Views
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
923 Views
Interface methods are contract with the outside world which specifies that class implementing this interface does a certain set of things.Interface members are always public because the purpose of an interface is to enable other types to access a class or struct.Interfaces can have access specifiers like protected or internal etc. Thus limiting 'the outside world' to a subset of 'the whole outside world'.Exampleinterface IInterface{ void Save(); } class Program{ static void Main(){ Console.ReadLine(); } }The above example will compile properly without any errorsPrior to C# 8, interface members were public by default. In ... Read More
2K+ Views
The main difference is StringBuilder is Mutable whereas String is Immutable.String is immutable, Immutable means if you create string object then you cannot modify it and It always create new object of string type in memory.On the other hand, StringBuilder is mutable. Means, if we create a string builder object then we can perform any operation like insert, replace or append without creating new instance for every time. It will update string at one place in memory doesn’t create new space in memory.Example Live Demousing System; using System.Text; class DemoApplication{ public static void Main(String[] args){ String systemString ... Read More
2K+ Views
Methods in C# are generally the block of codes or statements in a program which gives the user the ability to reuse the same code which ultimately saves the excessive use of memory, acts as a time saver and more importantly, it provides better readability of the code.There might be certain situations the user wants to execute a method but sometimes that method requires some valuable inputs in order to execute and complete its tasks. These input values are known as Parameters.Parameters can be passed to a method in the following ways −Value ParametersReference ParametersOutput ParametersValue ParametersValue Parameters copies the ... Read More
2K+ Views
Access modifiers are used to specify the scope of accessibility of a member of a class or type of the class itself. There are six different types of access modifiers.PublicPrivateProtectedInternalProtected InternalPrivate ProtectedPublic Access ModifierObjects that implement public access modifiers are accessible from everywhere in a project without any restrictions.Exampleusing System; namespace MyApplication{ public class Program{ public static void Main(){ Person person = new Person(); Console.WriteLine(person.Name); //Person Name is accessible as it is public } } public class Person{ ... Read More