
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
Found 2587 Articles for Csharp

3K+ Views
When more than one constructor with the same name is defined in the same class, they are called overloaded, if the parameters are different for each constructor.Let us see an example to learn how to work with Constructor Overloading in C#.In the example, we have two subjects and a string declaration for Student Name.private double SubjectOne; private double SubjectTwo; string StudentName;We are showing result of three students in different subjects. For our example, to show constructor overloading, the name is only displayed for student 3rd.Student s1 = new Student(); Student s2 = new Student(90); Student s3 = new Student("Amit", 88, ... Read More

4K+ Views
A compound assignment operator has a shorter syntax to assign the result. The operation is performed on the two operands before the result is assigned to the first operand.The following are the compound assignment operators in C#.Sr.NoOperator & Operator Name1+=Addition Assignment2-=Subtraction Assignment3*=Multiplication Assignment4/=Division Assignment5%=Modulo Assignment6&=Bitwise AND Assignment7|=Bitwise OR Assignment8^=Bitwise XOR Assignment9=Right Shift Assignment11=>Lambda OperatorLet us see an example to learn how to work with compound assignment operators in C#.Example Live Demousing System; namespace Program { class MyClass { public static void Main(string[] args) { int val = 7; val ... Read More

3K+ Views
CompositionUnder Composition, if the parent object is deleted, then the child object also loses its status. Composition is a special type of Aggregation and gives a part-of relationship.For example, A Car has an engine. If the car is destroyed, the engine is destroyed as well.public class Engine { . . . } public class Car { Engine eng = new Engine(); ....... }AggregationAggregation is a directional relation between objects in C#. It is the relationship between objects.For example, Employee and AddressAn Employee is associated with a single Department, whereas a Department can have more than one employee. Let us see ... Read More

21K+ Views
To compile and execute a program in C#, you just need to click the Run button or press F5 key to execute the project in Microsoft Visual Studio IDE. Compile a C# program by using the command-line instead of the Microsoft Visual Studio IDE − Open a text editor and add the above-mentioned code. Save the file as helloworld.cs Open the command prompt tool and go to the directory where you saved the file. Type csc helloworld.cs and press enter to compile your code. If there are no errors in your code, the command prompt takes you to the next line and ... Read More

3K+ Views
To work WITH and display complex numbers in C#, you need to check for real and imaginary values.A complex number like 7+5i is formed up of two parts, a real part 7, and an imaginary part 5. Here, the imaginary part is the multiple of i.To display complete numbers, use the −public struct ComplexTo add both the complex numbers, you need to add the real and imaginary part −public static Complex operator +(Complex one, Complex two) { return new Complex(one.real + two.real, one.imaginary + two.imaginary); }You can try to run the following code to work with complex numbers in ... Read More

2K+ Views
Get the array of the values of the constants in a specified enumeration.Here is our enum.enum Rank { Jack = 10, Tom = 19, Tim = 26 };Now, get all the values of the enum as an array and display using GetValues() method.foreach(int res in Enum.GetValues(typeof(Rank))) { Console.WriteLine(res); }Let us see the entire example.Example Live Demousing System; public class Demo { enum Rank { Jack = 10, Tom = 19, Tim = 26 }; public static void Main() { Console.WriteLine("Here are the university rank of MCA Students College ABC:"); foreach(int res in ... Read More

157 Views
Use the GetType() method to get the type of the enumeration.The enumeration.Enum[] values = { ConsoleColor.Blue, DayOfWeek.Sunday};Now to get the type, use the GetType() method.Type enumType = val.GetType();The following is an example that displays the type.Example Live Demousing System; public class Demo { public static void Main() { Enum[] values = { ConsoleColor.Blue, DayOfWeek.Sunday}; Console.WriteLine("{0, -5} {1, 10} {2, 10}", "Member", "Enumeration", "UnderlyingType"); foreach (var val in values) Info(val); } static void Info(Enum val) { Type enumType = val.GetType(); Type ... Read More

1K+ Views
The GetNames() returns the array of names of the constants in the Enumeration.The following is the enum.enum Stock { Watches, Books, Grocery };To get the array of names, use the GetNames() and loop through as shown below −foreach(string s in Enum.GetNames(typeof(Stock))) { }Let us see the complete example now.Example Live Demousing System; class Demo { enum Stock { Watches, Books, Grocery }; static void Main() { Console.WriteLine("The value of first stock category = {0}", Enum.GetName(typeof(Stock), 0)); Console.WriteLine("The value of second stock category = {0}", Enum.GetName(typeof(Stock), 1)); Console.WriteLine("The value of third ... Read More

2K+ Views
The GetName() method returns the names of the constants in the Enumeration.Here is the enum.enum Stock { Appliance, Clothing, Footwear };Now, get the names using the Enum.GetName() method. Just set the constant and retrieve the individual name.Enum.GetName(typeof(Stock), 1Let us see the example now.Example Live Demousing System; class Demo { enum Stock { Appliance, Clothing, Footwear }; static void Main() { Console.WriteLine("The value of second stock category = {0}", Enum.GetName(typeof(Stock), 1)); Console.WriteLine("The value of third stock category = {0}", Enum.GetName(typeof(Stock), 2)); } }OutputThe value of second stock category = Clothing The value of ... Read More

243 Views
Quadruple is a tuple with four items.Create a tuple first.var myTuple = Tuple.Create(100, 200, 300, 400);Above, we have created a tuple with four items i.e. Quadruple. Now to access all the four items.myTuple.Item1 myTuple.Item2 myTuple.Item3 myTuple.Item4Example Live Demousing System; public class Program { public static void Main() { var myTuple = Tuple.Create(100, 200, 300, 400); Console.WriteLine("Item1 : "+ myTuple.Item1); Console.WriteLine("Item2 : "+ myTuple.Item2); Console.WriteLine("Item3 : "+ myTuple.Item3); Console.WriteLine("Item4 : "+ myTuple.Item4); } }OutputItem1 : 100 Item2 : 200 Item3 : 300 Item4 : 400