Karthikeya Boyini has Published 2193 Articles

Removing whitespaces using C# Regex

karthikeya Boyini

karthikeya Boyini

Updated on 23-Jun-2020 08:25:19

2K+ Views

Let’s say we want to remove whitespace from the following string str1.string str1 = "Brad Pitt";Now, use Regex Replace to replace whitespace with empty. Here, we have used System.Text.RegularExpressions.string str2 = System.Text.RegularExpressions.Regex.Replace(str1, @"\s+", "");Let us see the complete example.Example Live Demousing System; using System.Text.RegularExpressions; namespace Demo {    class Program { ... Read More

C# Orderby Descending

karthikeya Boyini

karthikeya Boyini

Updated on 23-Jun-2020 08:23:07

380 Views

Use Orderby descending in C# to sort elements in descending order.The following is our list −IList emp = new List() { new Employee() { EmployeeRank = 3, EmpName = "Tom", EmpMarks = 90 } , new Employee() { EmployeeRank = 4, EmpName = "Katie", EmpMarks = 95 } };Now to ... Read More

C# Console BufferWidth Property

karthikeya Boyini

karthikeya Boyini

Updated on 23-Jun-2020 08:21:16

205 Views

Use the BufferWidth gets or sets the width of the buffer area.Use the property like this −Console.BufferWidthLet us see the complete example.Example Live Demousing System; class Demo {    static void Main() {       Console.WriteLine("Buffer width (columns) = "+Console.BufferWidth);    } }OutputBuffer width (columns) = 0

C# Linq Intersect Method

karthikeya Boyini

karthikeya Boyini

Updated on 23-Jun-2020 08:18:12

598 Views

Find common elements between two arrays using the Intersect() method.The following are our arrays −int[] val1 = { 15, 20, 40, 60, 75, 90 }; int[] val2 = { 17, 25, 35, 55, 75, 90 };To perform intersection.val1.AsQueryable().Intersect(val2);Let us see the entire example.Example Live Demousing System; using System.Collections.Generic; using System.Linq; class ... Read More

C# Queryable Max Method

karthikeya Boyini

karthikeya Boyini

Updated on 23-Jun-2020 08:15:18

209 Views

Get the maximum value from a sequence using the Max() method.Let’s say the following is our list.List list = new List { 200, 400, 600, 800, 1000, 1200, 1400, 1600, 1800, 2000 };Use the Max() method to get the largest element.list.AsQueryable().Max();Example Live Demousing System; using System.Collections.Generic; using System.Linq; class Demo { ... Read More

C# Program to find a key in a Hashtable

karthikeya Boyini

karthikeya Boyini

Updated on 23-Jun-2020 08:13:17

463 Views

Set Hashtable collection with elements.Hashtable h = new Hashtable(); h.Add(1, "Jack"); h.Add(2, "Henry"); h.Add(3, "Ben"); h.Add(4, "Chris");Let’s say now you need to find any key, then use the Contains() method. We are finding key 3 here −h.Contains(3);The following is the complete example.Example Live Demousing System; using System.Collections; public class Demo { ... Read More

ContainsKey() method in C#

karthikeya Boyini

karthikeya Boyini

Updated on 23-Jun-2020 08:11:40

288 Views

Set a Hashtable collection and add some elements to it.Hashtable h = new Hashtable(); h.Add(1, "Sam"); h.Add(2, "Jack"); h.Add(3, "Andy"); h.Add(4, "Katie"); h.Add(5, "Beth"); h.Add(6, "Benjamin");Use the ContainsKey() method to check whether a key exists in a Hashtable or not.Let’s check for key 3. It returns True of the key ... Read More

C# Program to get distinct element from a sequence

karthikeya Boyini

karthikeya Boyini

Updated on 23-Jun-2020 08:08:25

290 Views

Set a sequence and add elements.List ID = new List { 120, 111, 250, 111, 120, 300, 399, 450 };Use Distinct() method to get distinct element from the above list.IEnumerable res = ID.AsQueryable().Distinct();Let us see the complete code.Example Live Demousing System; using System.Linq; using System.Collections.Generic; class Demo {    static void ... Read More

C# Enum ToString() Method

karthikeya Boyini

karthikeya Boyini

Updated on 23-Jun-2020 08:06:27

3K+ Views

The ToString() method converts the value of this instance to its equivalent string representation.Firstly, set an enum.enum Vehicle { Car, Bus, Truck, Motobike };To convert it to an equivalent string representation, use ToString().Vehicle.Car.ToString("d")Example Live Demousing System; public class Demo {    enum Vehicle { Car, Bus, Truck, Motobike };    public ... Read More

What is the role of Browser Object Model (BOM) in JavaScript?

karthikeya Boyini

karthikeya Boyini

Updated on 23-Jun-2020 08:04:18

2K+ Views

The Browser Object Model (BOM) in JavaScript includes the properties and methods for JavaScript to interact with the web browser.BOM provides you with a window objects, for example, to show the width and height of the window. It also includes the window.screen object to show the width and height of ... Read More

Advertisements