Samual Sam has Published 2492 Articles

C# program to find additional values in two lists

Samual Sam

Samual Sam

Updated on 22-Jun-2020 15:20:42

214 Views

Firstly, set two lists in C#.List OneList list1 = new List (); list1.Add("P"); list1.Add("Q"); list1.Add("R"); list1.Add("S"); list1.Add("T"); list1.Add("U"); list1.Add("V"); list1.Add("W");List TwoList list2 = new List (); list2.Add("T"); list2.Add("U"); list2.Add("V"); list2.Add("W");Now, to get the different values in both the lists, use the Except method. It returns the ... Read More

C# program to find the length of the Longest Consecutive 1’s in Binary Representation of a given integer

Samual Sam

Samual Sam

Updated on 22-Jun-2020 15:17:23

232 Views

To fetch the consecutive 1’s, use the Bitwise Left Shift Operator. Here is our decimal number.i = (i & (i

How to validate a URL using regular expression in C#?

Samual Sam

Samual Sam

Updated on 22-Jun-2020 15:15:44

2K+ Views

To validate, you need to check for the protocols.http httpsWith that, you need to check for .com, .in, .org, etc.For this, use the following regular expression −(http|http(s)?://)?([\w-]+\.)+[\w-]+[.com|.in|.org]+(\[\?%&=]*)?The following is the code −Example Live Demousing System; using System.Text.RegularExpressions; namespace RegExApplication {    class Program {       private static void showMatch(string ... Read More

Removing whitespaces using C# String.Empty

Samual Sam

Samual Sam

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

65 Views

Set the string.StringBuilder str = new StringBuilder("Tom Hanks");Now, use the replace() method to replace whitespace with String. Empty. This will eventually remove the whitespace.str.Replace(" ", String.Empty);Let us see the complete code −Example Live Demousing System; using System.Text; class Demo {    static void Main() {       StringBuilder str = ... Read More

Manipulate decimals with numeric operators in C#

Samual Sam

Samual Sam

Updated on 22-Jun-2020 14:56:09

137 Views

With C#, you can manipulate decimals with operators such as _+, - *, etc.Let us see how to subtract decimal values.Firstly, set two decimal values −decimal d1 = 9.5M; decimal d2 = 4.2M;Now to subtract the two values −d1 = d1 - d2;The following is the code −Example Live Demousing System; ... Read More

C# Program to check if a character is a whitespace character

Samual Sam

Samual Sam

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

245 Views

Set a character with WhiteSpace −char c = ' ';To check if a character is a whitespace character, use the char.IsWhiteSpace method −if (char.IsWhiteSpace(c)) {}Let us see the complete code −Example Live Demousing System; class Demo {    static void Main() {       char c = ' ';   ... Read More

C# program to check whether two sequences are the same or not

Samual Sam

Samual Sam

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

140 Views

The SequenceEqual method is used to test collections for equality.Set sequences −string[] arr1 = { "This", "is", "it" }; string[] arr2 = { "My", "work", "report" }; string[] arr3 = { "This", "is", "it" };Now, use the SequenceEquals methods to check whether sequences are same or not −arr1.SequenceEqual(arr2);The following is ... Read More

Bool.parse method in C#

Samual Sam

Samual Sam

Updated on 22-Jun-2020 14:50:31

118 Views

To convert a string to a bool, use the Bool.parse method in C# −Firstly, set a string −string str = "true";Now, convert it to bool −bool.Parse(str);Here is the complete code −Example Live Demousing System; using System.Linq; class Demo {    static void Main() {       string str = "true"; ... Read More

C# program to remove all the numbers after decimal places

Samual Sam

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() {     ... Read More

Decimal type in C#

Samual Sam

Samual Sam

Updated on 22-Jun-2020 14:48:59

2K+ Views

The decimal type is a value type and has the plus, minus, multiply and divide operators.Firstly, set two decimal values −decimal d1 = 5.8M; decimal d2 = 3.2M;To add decimals −d1 = d1 + d2;Let us see an example to add two decimal values −Example Live Demousing System; using System.Linq; class ... Read More

Advertisements