Found 34494 Articles for Programming

C# Console.WindowWidth Property

karthikeya Boyini
Updated on 23-Jun-2020 09:05:38

271 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

Represent Int32 as a String in C#

Samual Sam
Updated on 23-Jun-2020 09:06:04

191 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

C# String.PadRight Method

George John
Updated on 23-Jun-2020 09:06:37

255 Views

Pad the end of the string with spaces using the PadRight() method. You can also pad it with a Unicode character.Let’s say the following is our string.string myStr = "Text1";To set a padding at the end of the above string, use the PadRight method.myStr.PadRight(10);Here is the complete example.Example Live Demousing System; class Demo {    static void Main() {       string myStr = "Text1";       // set padding at the end       Console.Write(myStr.PadRight(10));       Console.WriteLine("Text2");    } }OutputText1 Text2

C# Math.DivRem Method

karthikeya Boyini
Updated on 23-Jun-2020 09:07:46

155 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

C# Math.BigMul Method

Ankith Reddy
Updated on 23-Jun-2020 09:07:03

142 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

C# Linq First() Method

Samual Sam
Updated on 23-Jun-2020 08:58:52

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

Sortable ("s") Format Specifier in C#

Arjun Thakur
Updated on 23-Jun-2020 08:58:29

362 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

C# Linq ElementAt Method

karthikeya Boyini
Updated on 23-Jun-2020 08:59:17

224 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'

C# Linq Except Method

Chandu yadav
Updated on 23-Jun-2020 09:00:10

2K+ Views

Get the difference between two arrays using the Except() method.The following are the two arrays.int[] arr = { 9, 12, 15, 20, 35, 40, 55, 67, 88, 92 }; int[] arr2 = { 20, 35 };To get the difference, use Except() method that returns the first list, except the elements in the second list.arr.AsQueryable().Except(arr2);The following is the entire example.Example Live Demousing System; using System.Linq; using System.Collections.Generic; class Program {    static void Main() {       int[] arr = { 5, 10, 15, 20, 35, 40 };       int[] except = { 20, 35 };       ... Read More

FormatException in C#

Samual Sam
Updated on 23-Jun-2020 09:00:36

2K+ Views

FomatException is thrown when the format of an argument is invalid.Let us see an example.When we set a value other than int to int.Parse() method, then FormatException is thrown as shown below −Example Live Demousing System; class Demo {    static void Main() {       string str = "3.5";       int res = int.Parse(str);    } }The following error is thrown when the above program is compiled since we have passed a value other than integer.OutputUnhandled Exception: System.FormatException: Input string was not in a correct format.

Advertisements