Samual Sam has Published 2492 Articles

Compound assignment operators in C#

Samual Sam

Samual Sam

Updated on 23-Jun-2020 09:14:59

3K+ Views

A compound assignment operator has a shorter syntax to assign the result. The operation is performed on the two operands before the result is assigned to the first operand.The following are the compound assignment operators in C#.Sr.NoOperator & Operator Name1+=Addition Assignment2-=Subtraction Assignment3*=Multiplication Assignment4/=Division Assignment5%=Modulo Assignment6&=Bitwise AND Assignment7|=Bitwise OR Assignment8^=Bitwise XOR ... Read More

C# Enum CompareTo Method

Samual Sam

Samual Sam

Updated on 23-Jun-2020 09:12:25

324 Views

Compare two enums using the CompareTo() method in C#.The method returns any of the following value −Less than zero: Value of source is less than value of targetZero: Value of source is equal to the value of targetMore than zero: Value of source is more than value of targetExample Live Demousing ... Read More

Tuple Rest Property in C#

Samual Sam

Samual Sam

Updated on 23-Jun-2020 09:08:58

209 Views

Create tuples of eight or more elements by nesting tuple objects in the Rest property.The tuple would look like −TupleAbove, the 8th element is added using Rest property.Let us see an example.Example Live Demousing System; public class Program {    public static void Main() {       var myTuple = ... Read More

Represent Int32 as a String in C#

Samual Sam

Samual Sam

Updated on 23-Jun-2020 09:06:04

193 Views

Int32 represents a 32-bit signed integer. To represent it as a string, use the ToString() method.Firstly, declare and initialize an Int32 variable.int val = 1023;Now, represent it as a string.val.ToString()Let us see the complete example.Example Live Demousing System; class Demo {    static void Main() {       int val ... Read More

Convert.ToBoolean Method in C#

Samual Sam

Samual Sam

Updated on 23-Jun-2020 09:04:09

1K+ Views

The Convert.ToBoolean method is used to convert a specified value to an equivalent Boolean value.The following is our double type.double doubleNum = 329.34;To convert it to Boolean, use the Convert.ToBoolean() method.bool boolNum; boolNum = System.Convert.ToBoolean(doubleNum);Let us see another example.Example Live Demousing System; public class Demo {    public static void Main() ... Read More

"." custom specifier in C#

Samual Sam

Samual Sam

Updated on 23-Jun-2020 09:02:33

159 Views

The "." custom format specifier adds a localized decimal separator into the output string.The 1st period in the format string determines the location of the decimal separator in the formatted value.double d = 2.3; d.ToString("0.00", CultureInfo.InvariantCultureLet us see another example to learn how to implement “.” Custom specifier.Example Live Demousing System; ... Read More

FormatException in C#

Samual Sam

Samual Sam

Updated on 23-Jun-2020 09:00:36

2K+ Views

FomatException is thrown when the format of an argument is invalid.Let us see an example.When we set a value other than int to int.Parse() method, then FormatException is thrown as shown below −Example Live Demousing System; class Demo {    static void Main() {       string str = "3.5"; ... Read More

C# Linq First() Method

Samual Sam

Samual Sam

Updated on 23-Jun-2020 08:58:52

3K+ Views

Use the First() method to get the first element from an array.Firstly, set an array.int[] arr = {20, 40, 60, 80 , 100};Now, use the Queryable First() method to return the first element.arr.AsQueryable().First();The following is the entire example.Example Live Demousing System; using System.Linq; using System.Collections.Generic; class Program {    static void ... Read More

C# DefaultIfEmpty Method

Samual Sam

Samual Sam

Updated on 23-Jun-2020 08:56:58

215 Views

This method is used to handle empty collections. Instead of showing an error, this method displays a default value.We have the following list.List myList = new List();As you can see, since the above list is empty, we can display the default value.var res = myList.DefaultIfEmpty();Let us see an example.Example Live Demousing ... Read More

Represent Int64 as a String in C#

Samual Sam

Samual Sam

Updated on 23-Jun-2020 08:50:51

188 Views

Int64 represents a 64-bit signed integer. To represent it as a string, use the ToString() method.Firstly, declare and initialize an Int64 variable.long val = 8766776;Now, represent it as a string.val.ToString()Let us see the complete example.Example Live Demousing System; class Demo {    static void Main() {       long val ... Read More

Advertisements