- 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 34488 Articles for Programming
![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)
183 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)
212 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
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
580 Views
The Format method converts value of a specified enumerated type to its equivalent string representation. Here you can also set the format i.e. d for Decimal, x for HexaDecimal, etc.We have the following enumeration.enum Stock { PenDrive, Keyboard, Speakers };The default value gets assigned (initialize).PenDrive = 0 Keyboard = 1 Speakers = 2Now, let’s say you want the value of “Keyboard” name.Stock st = Stock.Keyboard;For that, try the following and get the constant value for Keyboard name.Enum.Format(typeof(Stock), st, "d")The following is the entire example.Example Live Demousing System; class Demo { enum Stock { PenDrive, Keyboard, Speakers }; static void ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
219 Views
Convert a specified value to a 32-bit unsigned integer using the Convert.ToUInt32 method.The following is our string.string str = "210";Now, let us convert it to a 32-bit unsigned integer.uint res; res = Convert.ToUInt32(str);Example Live Demousing System; public class Demo { public static void Main() { string str = "210"; uint res; res = Convert.ToUInt32(str); Console.WriteLine("Converted string '{0}' to {1}", str, res); } }OutputConverted string '210' to 210
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
599 Views
To find the equality between enums, use the Equals() method.Let’s say we have the following Enum.enum Products { HardDrive, PenDrive, Keyboard};Create two Products objects and assign the same values.Products prod1 = Products.HardDrive; Products prod2 = Products.HardDrive;Now check for equality using Equals() method. It would be True since both have the same underlying value.Example Live Demousing System; class Program { enum Products {HardDrive, PenDrive, Keyboard}; enum ProductsNew { Mouse, HeadPhone, Speakers}; static void Main() { Products prod1 = Products.HardDrive; Products prod2 = Products.HardDrive; ProductsNew newProd1 = ProductsNew.HeadPhone; ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
326 Views
Compare two enums using the CompareTo() method in C#.The method returns any of the following value −Less than zero: Value of source is less than value of targetZero: Value of source is equal to the value of targetMore than zero: Value of source is more than value of targetExample Live Demousing System; class Program { enum Products { HardDrive = 0, PenDrive = 4, Keyboard = 8 }; static void Main() { Products prod1 = Products.HardDrive; Products prod2 = Products.PenDrive; Products prod3 = Products.Keyboard; Console.WriteLine("Stock for {0} ... Read More