
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

1K+ 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

2K+ 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.

3K+ 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

399 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

292 Views
Int32 represents a 32-bit signed integer. To represent it as a string, use the ToString() method.Firstly, declare and initialize an Int32 variable.int val = 1023;Now, represent it as a string.val.ToString()Let us see the complete example.Example Live Demousing System; class Demo { static void Main() { int val = 1023; Console.Write("Integer converted to string = "+val.ToString()); } }OutputInteger converted to string = 1023

209 Views
Use the Math.DivRem method to calculate the quotient of two numbers and return the remainder.Firstly, set dividend and divisor.// dividend long dividend = 30; // divisor long divisor = 7;Now, use the DivRem method.long quotient = Math.DivRem(dividend, divisor, out rem);Example Live Demousing System; using System.Globalization; class Demo { static void Main() { // remainder long rem; // dividend long dividend = 98; // divisor long divisor = 9; long quotient = Math.DivRem(dividend, divisor, out rem); Console.WriteLine("{0} \ {1} = {2} and remainder = {3}", dividend, divisor, quotient, rem); } }Output98 \ 9 = 10 and remainder = 8

200 Views
Use the Math.BigMul() method to find the product of two 32-bit numbers.The following are our two numbers.int one = 345272828; int two = 887685744;Now, get the product.long res; res = Math.BigMul(one, two);Example Live Demousing System; using System.Globalization; class Demo { static void Main() { int one = 345272828; int two = 887685744; long res; res = Math.BigMul(one, two); Console.WriteLine("{0} * {1} = {2}", one, two, res); } }Output345272828 * 887685744 = 306493767206164032

3K+ Views
Use the First() method to get the first element from an array.Firstly, set an array.int[] arr = {20, 40, 60, 80 , 100};Now, use the Queryable First() method to return the first element.arr.AsQueryable().First();The following is the entire example.Example Live Demousing System; using System.Linq; using System.Collections.Generic; class Program { static void Main() { int[] arr = {20, 40, 60, 80 , 100}; // getting the first element int res = arr.AsQueryable().First(); Console.WriteLine(res); } }Output20

509 Views
The Sortable standard format specifier represents a custom date and time format string.The format string is defined by the DateTimeFormatInfo.SortableDateTimePattern property.The custom format string.yyyy'-'MM'-'dd'T'HH':'mm':'ssExample Live Demousing System; class Demo { static void Main() { DateTime date = new DateTime(2018, 9, 5, 2, 12, 40); Console.WriteLine(date.ToString("s")); } }Output2018-09-05T02:12:40

308 Views
The ElementAt() method in C# to get elements at specified index position.Firstly, set the string array.string[] str = { "Jack", "Pat", "David"};Now, to get the element at a particular index, use the ElementAt() method as shown in the following example −Example Live Demousing System.IO; using System; using System.Linq; class Program { static void Main() { string[] str = { "Jack", "Pat", "David"}; Random r = new Random(DateTime.Now.Second); // to generate random string string res = str.AsQueryable().ElementAt(r.Next(0, str.Length)); Console.WriteLine("Random Name = '{0}'", res); } }OutputRandom Name = 'Jack'