Found 2628 Articles for Csharp

Type.GetNestedTypes() Method in C#

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

64 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

74 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

30 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

138 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

66 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

Int16.MaxValue Field in C# with Examples

AmitDiwan
Updated on 11-Nov-2019 06:50:06

141 Views

The Int16.MaxValue field in C# represents the largest possible value of an Int16.SyntaxFollowing is the syntax −public const short MaxValue = 32767;ExampleLet us now see an example to implement the Int16.MaxValue 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

Int16.GetTypeCode Method in C# with Examples

AmitDiwan
Updated on 11-Nov-2019 06:45:31

57 Views

The Int16.GetTypeCode() method in C# is used to return the TypeCode for value type Int16.SyntaxFollowing is the syntax −public TypeCode GetTypeCode ();ExampleLet us now see an example to implement the Int16.GetTypeCode() method −using System; public class Demo {    public static void Main(){       short val1 = 0;       short val2 = Int16.MaxValue;       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

Int16.GetHashCode() Method in C# with Examples

AmitDiwan
Updated on 11-Nov-2019 06:43:06

59 Views

The Int16.GetHashCode() method in C# is used to return the hash code for the current instance.SyntaxFollowing is the syntax −public override int GetHashCode ();ExampleLet us now see an example to implement the Int16.GetHashCode() method −using System; public class Demo {    public static void Main(){       short val1 = 20;       short val2 = 25;       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)));    } }OutputThis will produce ... Read More

DateTime.AddTicks() Method in C#

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

667 Views

The DateTime.AddTicks() method in C# is used to add a specified number of ticks to the value of this instance. It returns a new DateTime.SyntaxFollowing is the syntax −public DateTime AddTicks (long ticks);Here, ticks value is for 100-nanosecond.ExampleLet us now see an example to implement the DateTime.AddTicks() method −using System; public class Demo {    public static void Main(){       DateTime d1 = new DateTime(2019, 07, 25, 6, 20, 40);       DateTime d2 = d1.AddTicks(5000);       System.Console.WriteLine("DateTime = {0:dd} {0:y}, {0:hh}:{0:mm}:{0:ss} ", d1);       System.Console.WriteLine("Initial Ticks = {0} ", d1.Ticks);     ... Read More

DateTime.AddSeconds() Method in C#

AmitDiwan
Updated on 11-Nov-2019 05:58:09

2K+ Views

The DateTime.AddSeconds() method in C# is used to add the specified number of seconds to the value of this instance. This returns a new DateTime.SyntaxFollowing is the syntax −public DateTime AddSeconds (double sec);Here, sec is the seconds to be added. If you want to subtract seconds, then set a negative value.ExampleLet us now see an example to implement the DateTime.AddSeconds() method −using System; public class Demo {    public static void Main(){       DateTime d1 = new DateTime(2019, 10, 25, 6, 20, 40);       DateTime d2 = d1.AddSeconds(25);       System.Console.WriteLine("Initial DateTime = {0:dd} {0:y}, ... Read More

Advertisements