George John has Published 1167 Articles

C# Program to match all the digits in a string

George John

George John

Updated on 22-Jun-2020 14:53:57

319 Views

To match all digits in a string, use C# Regex.Firstly, set a string with digits −string str = "These are my marks: 90 out of 100!";Use the following regular expression to get digits in a string −@"\d+"The following is the code −Example Live Demousing System; using System.Text.RegularExpressions; namespace Demo {   ... Read More

CSS position: fixed;

George John

George John

Updated on 22-Jun-2020 14:51:03

473 Views

The position: fixed; property allows you to position element relative to the viewport. You can try to run the following code to implement CSS position: fixed;ExampleLive Demo                    div{             position: fixed;       ... Read More

Any Extension method in C#

George John

George John

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

358 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 ... Read More

Tuple.Create method in C#

George John

George John

Updated on 22-Jun-2020 14:45:08

83 Views

To create a tuple, use the Tuple.Create method.Here we have set a tuple with a string and int −var myTuple = Tuple.Create("marks", 100);The following is an example that creates a tuple using Tuple.Create and displays the elements in a single line in C# −Example Live Demousing System; class Demo {   ... Read More

C# Program to get the name of root directory

George John

George John

Updated on 22-Jun-2020 14:33:02

506 Views

Use the RootDirectory property to get the name of the root directory.Firstly, use DriveInfo to set the drive for which you want the root directory −DriveInfo dInfo = new DriveInfo("C");Now, the RootDirectory gives you the result −dInfo.RootDirectoryExampleHere is the complete code −using System; using System.Linq; using System.IO; public class Demo ... Read More

Aggregate method in C#

George John

George John

Updated on 22-Jun-2020 14:30:53

830 Views

Use the Aggregate method in C# to perform mathematical operations such as Sum, Min, Max, Average, etc.Let us see an example to multiply array elements using Aggregate method.Here is our array −int[] arr = { 10, 15, 20 };Now, use Aggregate() method −arr.Aggregate((x, y) => x * y);Here is the ... Read More

C# orderby Keyword

George John

George John

Updated on 22-Jun-2020 14:26:38

133 Views

Use the orderby leyword to sort a list in ascending or descending order.The following is the list −List myList = new List(); myList.Add("truck"); myList.Add("bus"); myList.Add("bicycle"); myList.Add("motorbike");Now let us sort the list in descending order −myLen = from element in myList orderby element.Length descending select element;Here is the complete code −Example Live ... Read More

Stopwatch class in C#

George John

George John

Updated on 22-Jun-2020 14:19:14

2K+ Views

Stopwatch is a class in C# to measure the elapsed time. Use it to calculate the time a function took to execute. It is found under System.Diagnostics.To get the elapsed time, firstly begin the Stopwatch −var sw = Stopwatch.StartNew();For elapsed ticks −long ticks = sw.ElapsedTicks;Let us see an example −Example Live ... Read More

Ulong type in C#

George John

George John

Updated on 22-Jun-2020 14:17:34

602 Views

The Ulong type in C# is an alias to the System.UInt64 type. It is an Unsigned integer.Set the Ulong type −ulong val = 7712059531;To get the minimum and maximum value for Ulong type −Console.WriteLine(ulong.MaxValue); Console.WriteLine(ulong.MinValue);Here is the complete code −Example Live Demousing System; using System.Threading; using System.Diagnostics; public class Demo { ... Read More

KeyValuePair in C#

George John

George John

Updated on 22-Jun-2020 14:15:06

10K+ Views

The KeyValuePair class stores a pair of values in a single list with C#.Set KeyValuePair and add elements −var myList = new List(); // adding elements myList.Add(new KeyValuePair("Laptop", 20)); myList.Add(new KeyValuePair("Desktop", 40)); myList.Add(new KeyValuePair("Tablet", 60));Here is the code to learn how to work with KeyValuePair and display the keys ... Read More

Advertisements