Long Parse Method in C#

karthikeya Boyini
Updated on 22-Jun-2020 14:50:11

2K+ Views

To convert a string to a long, use the Long.parse method in C# −Firstly, set a string −string str = "7864646475767";Now, convert it to long −long.Parse(str);Here is the complete code −Example Live Demousing System; using System.Linq; class Demo {    static void Main() {       string str = "7864646475767";       long res = long.Parse(str);       Console.WriteLine(res);    } }Output7864646475767

Remove All Numbers After Decimal Places in C#

Samual Sam
Updated on 22-Jun-2020 14:49:48

4K+ Views

Use the Truncate method in C# to remove all the number after decimal places.Let’s say the following is our number −9.15MTo remove the numbers after decimal places, use Truncate() −decimal.Truncate(9.15M)Let us see the complete code −Example Live Demousing System; using System.Linq; class Demo {    static void Main() {       decimal val = 9.15M;       Console.WriteLine(decimal.Truncate(val));    } }Output9

Round a Number to the Nearest Even Number in C#

karthikeya Boyini
Updated on 22-Jun-2020 14:49:23

796 Views

The ToEven property is used with the MidpointRounding Enumeration to round a number to the nearest even number.Declare and initialize a decimal number −decimal val = 25.55M;To round a number to the nearest even number −decimal.Round(val, 0, MidpointRounding.ToEven)Here is the complete code −Example Live Demousing System; using System.Linq; class Demo {    static void Main() {       decimal val = 25.55M;       Console.WriteLine(decimal.Round(val, 0, MidpointRounding.ToEven));    } }Output26

Decimal Constants in C#

karthikeya Boyini
Updated on 22-Jun-2020 14:48:39

3K+ Views

Decimal type has constants to get the minimum and maximum values.Set a decimal value −decimal d = 5.8M;To get the minimum and maximum values of the decimal type, use the following properties −decimal.MaxValue decimal.MinValueHere is the complete code −Example Live Demousing System; using System.Linq; class Demo {    static void Main() {       decimal d = 5.8M;       Console.WriteLine(d);       Console.WriteLine("Maximum Value: "+decimal.MaxValue);       Console.WriteLine("Maximum Value: "+decimal.MinValue);    } }Output5.8 Maximum Value: 79228162514264337593543950335 Maximum Value: -79228162514264337593543950335

Any Extension Method in C#

George John
Updated on 22-Jun-2020 14:47:54

490 Views

The Any() extension method is part of the System.Linq namepspace. Using this method, you can check whether any of the elements matches a certain condition or not.Firstly, set an array with elements −int[] arr = { 6, 7, 15, 40, 55 };The following is an example. It checks whether any of the element in the array is greater than and equal to 20 or not −arr.Any(element => element >= 20);Here is the complete code −Example Live Demousing System; using System.Linq; class Program {    static void Main() {       int[] arr = { 6, 7, 15, 40, 55 };       bool res = arr.Any(element => element >= 20);       Console.WriteLine(res);    } }OutputTrue

Role of CSS :checked Selector

radhakrishna
Updated on 22-Jun-2020 14:47:45

253 Views

Use the CSS :checked selector to style every checked element. You can try to run the following code to implement the :checked selector:ExampleLive Demo                    input:checked {             height: 20px;             width: 20px;          }                     Fav sports:                Football          Cricket           Tennis          Tennis           Output

SequenceEqual Method in C#

Ankith Reddy
Updated on 22-Jun-2020 14:47:37

538 Views

The SequenceEqual method is used to test collections for equality.Let us set three string arrays −string[] arr1 = { "This", "is", "it" }; string[] arr2 = { "My", "work", "report" }; string[] arr3 = { "This", "is", "it" };Now, compare the first array with the second using the SequenceEqual() method −arr1.SequenceEqual(arr2);The following is an example −Example Live Demousing System; using System.Linq; class Program {    static void Main() {       string[] arr1 = { "This", "is", "it" };       string[] arr2 = { "My", "work", "report" };       string[] arr3 = { "This", "is", "it" };       bool res1 = arr1.SequenceEqual(arr2);       Console.WriteLine(res1);       bool res2 = arr1.SequenceEqual(arr3);       Console.WriteLine(res2);    } }OutputFalse True

C# Program to Display a String in Reverse Alphabetic Order

Arjun Thakur
Updated on 22-Jun-2020 14:46:49

846 Views

Set a string array and convert it to character array −string str = "Amit"; char[] arr = str.ToCharArray();Now, use the Reverse method to display the above string in reverse alphabetic order −Array.Reverse(arr);Here is the complete code −Example Live Demousing System; using System.Linq; using System.IO; class Program {    static void Main() {       string str = "Amit";       char[] arr = str.ToCharArray();       Console.WriteLine("Original String: "+str);       // Reverse       Array.Reverse(arr);       Console.WriteLine("Reversed String: "+new string(arr));    } }OutputOriginal String: Amit Reversed String: timA

C# Program to Split a String on Spaces

Chandu yadav
Updated on 22-Jun-2020 14:46:25

2K+ Views

Firstly, set a string −string str = "Science and Mathematics";Now use the Split() method to split wherever the spaces occur −str.Split(' ')The following is the complete code −Example Live Demousing System; using System.Linq; using System.IO; class Program {    static void Main() {       string str = "Science and Mathematics";       Console.WriteLine("String..."+str);       string[] myStr = str.Split(' ');       Console.WriteLine("Splitted String...");       foreach (string ch in myStr) {          Console.WriteLine(ch);       }    } }OutputString... Science and Mathematics Splitted String... Science and Mathematics

C# Program to Split Parts in a Windows Directory

Arjun Thakur
Updated on 22-Jun-2020 14:46:00

801 Views

Firstly, set a string i.e. your Windows directory path −string str = @"D:\Downloads\Amit";Now use the Split() method and split wherever the \ occur −str.Split(' \')The following is the complete code −Example Live Demousing System; class Program {    static void Main() {       string str = @"D:\Downloads\Amit";       Console.WriteLine("Directory..."+str);       string[] myStr = str.Split('\');       Console.WriteLine("Split...");       foreach (string ch in myStr) {          Console.WriteLine(ch);       }    } }OutputDirectory... D:\Downloads\Amit Split... D: Downloads Amit

Advertisements