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
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
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 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
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
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
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
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
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
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
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP