- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 2628 Articles for Csharp
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
2K+ 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
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
1K+ 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
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
109 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
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
817 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
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
1K+ 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
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
181 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
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
209 Views
Create tuples of eight or more elements by nesting tuple objects in the Rest property.The tuple would look like −TupleAbove, the 8th element is added using Rest property.Let us see an example.Example Live Demousing System; public class Program { public static void Main() { var myTuple = Tuple.Create(1, 2.5M, "Tom", "100", 5, 10.5M, "Henry", "100"); Console.WriteLine("Item1 : "+ myTuple.Item1); Console.WriteLine("Item2 : "+ myTuple.Item2); Console.WriteLine("Item3 : "+ myTuple.Item3); Console.WriteLine("Item4 : "+ myTuple.Item4); Console.WriteLine("Item5 : "+ myTuple.Item5); Console.WriteLine("Item6 : "+ myTuple.Item6); ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
258 Views
Create a tuple.var myTuple = Tuple.Create(1, 2.5M, "Amit", "100");Now to access tuple elements, use the properties.To access first element.myTuple.Item1To access second element.myTuple.Item2In the same way, for other elements, use the properties as shown below −Example Live Demousing System; public class Program { public static void Main() { var myTuple = Tuple.Create(1, 2.5M, "Amit", "100"); Console.WriteLine("Item1 : "+ myTuple.Item1); Console.WriteLine("Item2 : "+ myTuple.Item2); Console.WriteLine("Item3 : "+ myTuple.Item3); Console.WriteLine("Item4 : "+ myTuple.Item4); } }OutputItem1 : 1 Item2 : 2.5 Item3 : Amit Item4 : 100
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
114 Views
It occurs when Index is outside the bounds of the array.Let us see an example. We have declare an array with 5 elements and set the size as 5.int[] arr = new int[5]; arr[0] = 10; arr[1] = 20; arr[2] = 30; arr[3] = 40; arr[4] = 50;Now, we try to add the value of an element that extends the size of our array i.e.arr[5] = 60;Above, we are trying to add element at 6th position.Example Live Demousing System; using System.IO; using System.Collections.Generic; namespace Demo { class Program { static void Main(string[] args) { ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
110 Views
Set an array and arrange it in descending order using OrderByDescending.int[] prod = { 290, 340, 129, 540, 456, 898, 765, 789, 345};Now, use the Take() method to return specified number of elements from the beginning.Enumerable units = prod.AsQueryable().OrderByDescending(s => s).Take(2);Let us see the complete code.Example Live Demousing System; using System.Linq; using System.Collections.Generic; public class Demo { public static void Main() { int[] prod = { 290, 340, 129, 540, 456, 898, 765, 789, 345}; // Volume of top two products IEnumerable units = prod.AsQueryable().OrderByDescending(s => s).Take(2); foreach (int res in units) { Console.WriteLine(res); } } }Output898 789