- 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
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
576 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)
218 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)
324 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
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
1K+ Views
Get the last element from a sequence using the Linq Last() method.The following is our array.int[] val = { 10, 20, 30, 40 };Now, get the last element.val.AsQueryable().Last();Example Live Demousing System; using System.Collections.Generic; using System.Linq; class Demo { static void Main() { int[] val = { 10, 20, 30, 40 }; // getting last element int last_num = val.AsQueryable().Last(); Console.WriteLine("Last element: "+last_num); } }OutputLast element: 40
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
140 Views
Use the Convert.ToUInt64() method to convert a specified value to a 64-bit unsigned integer.The following is our char.char ch = 'a';Now, let’s convert it to a 64-bit unsigned integer.ulong res; res = Convert.ToUInt64(ch);Here is the complete example.Example Live Demousing System; public class Demo { public static void Main() { char ch = 'a'; ulong res; res = Convert.ToUInt64(ch); Console.WriteLine("Converted char value '{0}' to {1}", ch, res); } }OutputConverted char value 'a' to 97
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
852 Views
The Convert.ToByte method is used to convert a specified value to an 8-bit unsigned integer.Let’s say we have a char variable.Char charVal = ‘a’;Now, convert it to an 8-bit unsigned integer.byte byteVal = Convert.ToByte(charVal);Let us see another example now.Example Live Demousing System; public class Demo { public static void Main() { char[] charVal = { 'p', 'q', 'r', 's' }; foreach (char c in charVal) { byte byteVal = Convert.ToByte(c); Console.WriteLine("{0} is converted to = {1}", c, byteVal); } } }Outputp is converted to = 112 q is converted to = 113 r is converted to = 114 s is converted to = 115
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
1K+ Views
The Convert.ToBoolean method is used to convert a specified value to an equivalent Boolean value.The following is our double type.double doubleNum = 329.34;To convert it to Boolean, use the Convert.ToBoolean() method.bool boolNum; boolNum = System.Convert.ToBoolean(doubleNum);Let us see another example.Example Live Demousing System; public class Demo { public static void Main() { double doubleNum = 3.4; bool boolNum; // Double to bool boolNum = System.Convert.ToBoolean(doubleNum); System.Console.WriteLine("{0} as a Boolean = {1}.", doubleNum, boolNum); } }Output3.4 as a Boolean = True.
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
2K+ Views
The ChangeType() method returns an object of the specified type and whose value is equivalent to the specified object.Let’s say we have a double type.double val = -3.456Now, use the ChangeType method to change the type to integer.num = (int)Convert.ChangeType(val, TypeCode.Int32);Let us see the complete example.Example Live Demousing System; public class Demo { public static void Main() { double val = -3.456; int num = (int)Convert.ChangeType(val, TypeCode.Int32); Console.WriteLine("{0} converted to an Int32: {1}", val, num); } }Output-3.456 converted to an Int32: -3
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
272 Views
The WindowWidth property gets or sets the width of the console window.Declare a variable.int width;Now, get the width of the current window.width = Console.WindowWidth;The following is the complete example.Example Live Demousing System; using System.Numerics; using System.Globalization; class Demo { static void Main() { int width; int height; width = Console.WindowWidth; height = Console.WindowHeight; Console.WriteLine("Current window width = "+width); Console.WriteLine("Current window height = "+height); } }OutputCurrent window width = 0 Current window height = 0