Found 2587 Articles for Csharp

Boolean.Equals(Boolean) Method in C#

AmitDiwan
Updated on 11-Nov-2019 07:23:45

465 Views

The Boolean.Equals(Boolean) method in C# returns a value indicating whether this instance is equal to a specified Boolean object.SyntaxFollowing is the syntax −public bool Equals (bool ob);Above, ob is a Boolean value to compare to this instance.ExampleLet us now see an example to implement the Boolean.Equals(Boolean) method −using System; public class Demo {    public static void Main(){       bool b1 = false;       bool b2 = true;       bool res = b1.Equals(b2);       if (res == true)          Console.Write("b1 equal to b2");       else     ... Read More

DateTimeOffset.AddMilliseconds() Method in C#

AmitDiwan
Updated on 11-Nov-2019 07:21:58

97 Views

The DateTimeOffset.AddMilliseconds() method in C# is used to return a new DateTimeOffset object that adds a specified number of milliseconds to the value of this instance.SyntaxFollowing is the syntax −public DateTimeOffset AddMilliseconds (double val);Above, Val are the milliseconds to be added. To subtract, set a negative value.ExampleLet us now see an example to implement the DateTimeOffset.AddMilliseconds() method −using System; public class Demo {    public static void Main() {       DateTimeOffset dateTimeOffset = new DateTimeOffset(2019, 08, 10, 4, 20, 10, new TimeSpan(-5, 0, 0));       Console.WriteLine("DateTimeOffset (before adding milliseconds) = {0}", dateTimeOffset);       DateTimeOffset ... Read More

DateTimeOffset.AddHours() Method in C#

AmitDiwan
Updated on 11-Nov-2019 07:13:13

283 Views

The DateTimeOffset.AddHours() method in C# is used to add a specified number of whole and fractional hours to the value of this instance.SyntaxFollowing is the syntax −public DateTimeOffset AddHours (double hrs);Above, hrs are the hours to be added. To subtract hours, include a negative value.ExampleLet us now see an example to implement the DateTimeOffset.AddHours() method −using System; public class Demo {    public static void Main() {       DateTimeOffset dateTimeOffset = new DateTimeOffset(2019, 10, 10, 3, 15, 0, new TimeSpan(-5, 0, 0));       Console.WriteLine("DateTimeOffset (before adding hours) = {0}", dateTimeOffset);       DateTimeOffset res = ... Read More

DateTimeOffset.AddDays() Method in C#

AmitDiwan
Updated on 11-Nov-2019 07:10:43

481 Views

The DateTimeOffset.AddDays() method in C# is used to return a new DateTimeOffset object that adds a specified number of whole and fractional days to the value of this instance.SyntaxFollowing is the syntax −public DateTimeOffset AddDays (double val);Above, Val is the number of days to be added. To subtract, include a negative value.ExampleLet us now see an example to implement the DateTimeOffset.AddDays() method −using System; public class Demo {    public static void Main() {       DateTimeOffset dateTimeOffset = new DateTimeOffset(2019, 10, 10, 9, 15, 0, new TimeSpan(-5, 0, 0));       DateTimeOffset res = dateTimeOffset.AddDays(20);     ... Read More

DateTimeOffset.Add() Method in C#

AmitDiwan
Updated on 11-Nov-2019 07:08:22

106 Views

The DateTimeOffset.Add() method in C# is used to return a new DateTimeOffset object that adds a specified time interval to the value of this instance.SyntaxFollowing is the syntax −public DateTimeOffset Add (TimeSpan t);ExampleLet us now see an example to implement the DateTimeOffset.Add() method −using System; public class Demo {    public static void Main() {       DateTimeOffset dateTimeOffset = new DateTimeOffset(2019, 10, 10, 9, 45, 20, new TimeSpan(-10, 0, 0));       TimeSpan ts = new TimeSpan(20, 0, 0);       DateTimeOffset res = dateTimeOffset.Add(ts);       Console.WriteLine("DateTimeOffset = {0}", res);    } }OutputThis will ... Read More

Type.GetNestedTypes() Method in C#

AmitDiwan
Updated on 11-Nov-2019 07:05:45

115 Views

The Type.GetNestedTypes() method in C# is used to get the types nested within the current Type.SyntaxFollowing is the syntax −public Type[] GetNestedTypes (); public abstract Type[] GetNestedTypes (System.Reflection.BindingFlags bindingAttr);ExampleLet us now see an example to implement the Type.GetNestedTypes() method −using System; public class Demo {    public static void Main(){       Type type1 = typeof(Subject);       try {          Type[] type2 = type1.GetNestedTypes();          Console.WriteLine("Nested Types...");          for (int i = 0; i < type2.Length; i++)             Console.WriteLine("{0} ", type2[i]);     ... Read More

Type.GetNestedType() Method in C#

AmitDiwan
Updated on 11-Nov-2019 07:00:36

145 Views

The Type.GetNestedType() method in C# is used to get a specific type of nested within the current Type.SyntaxFollowing is the syntax −public Type GetNestedType (string name); public abstract Type GetNestedType (string name, System.Reflection.BindingFlags bindingAttr);ExampleLet us now see an example to implement the Type.GetNestedType() method −using System; public class Demo {    public static void Main(){       Type type1 = typeof(Subject);       try {          Type type2 = type1.GetNestedType("AdvSubject");          Console.Write("NestedType = "+ type2);       }       catch (ArgumentNullException e){          Console.Write("{0}", e.GetType(), e.Message); ... Read More

Decimal.FromOACurrency() Method in C#

AmitDiwan
Updated on 11-Nov-2019 06:58:19

78 Views

The Decimal.FromOACurrency() method in C# is used to convert the specified 64-bit signed integer, which contains an OLE Automation Currency value, to the equivalent Decimal valueSyntaxFollowing is the syntax −public static decimal FromOACurrency (long val);Above, Val is an OLE Automation Currency value.ExampleLet us now see an example to implement the Decimal.FromOACurrency() method −using System; public class Demo {    public static void Main(){       long val = 978576L;       decimal res = Decimal.FromOACurrency(val);       Console.WriteLine("Decimal Value = "+ res);    } }OutputThis will produce the following output −Decimal Value = 97.8576ExampleLet us now see ... Read More

Int32.CompareTo Method in C# with Examples

AmitDiwan
Updated on 11-Nov-2019 06:56:40

229 Views

The Int32.CompareTo method in C# is used to compare this instance to a specified object or Int32 and returns an indication of their relative values.SyntaxFollowing is the syntax −public int CompareTo (int val); public int CompareTo (object val);Above, the value of the 1st syntax is an integer to compare, whereas, in the 2nd syntax, it is an object to compare.The return value is less than zero if the current instance is less than the value. It’s zero, if the current instance is equal to value, whereas return value is more than zero if the current instance is more than value.ExampleLet ... Read More

Int16.MinValue Field in C# with Examples

AmitDiwan
Updated on 11-Nov-2019 06:52:36

134 Views

The Int16.MinValue field in C# represents the smallest possible value of an Int16.SyntaxFollowing is the syntax −public const short MinValue = -32768;ExampleLet us now see an example to implement the Int16.MinValue field −using System; public class Demo {    public static void Main(){       short val1 = 23;       short val2 = 0;       Console.WriteLine("Value1 = "+val1);       Console.WriteLine("Value2 = "+val2);       Console.WriteLine("HashCode for value1 = "+val1.GetHashCode());       Console.WriteLine("HashCode for value2 = "+val2.GetHashCode());       Console.WriteLine("Are they equal? = "+(val1.Equals(val2)));       TypeCode type1 = val1.GetTypeCode(); ... Read More

Advertisements