Found 2587 Articles for Csharp

Int16.MaxValue Field in C# with Examples

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

226 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

103 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

97 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

859 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

3K+ 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

DateTime.AddMonths() Method in C#

AmitDiwan
Updated on 11-Nov-2019 05:56:20

5K+ Views

The DateTime.AddMonths() method in C# is used to add the specified number of months to the value of this instance.SyntaxFollowing is the syntax −public DateTime AddMonths (int val);Above, Val is the number of months. If you want to subtract months, then set it as negative.ExampleLet us now see an example to implement the DateTime.AddMonths() method −using System; public class Demo {    public static void Main(){       DateTime d1 = new DateTime(2019, 05, 15, 5, 15, 25);       DateTime d2 = d1.AddMonths(5);       System.Console.WriteLine("Initial DateTime = {0:dd} {0:y}, {0:hh}:{0:mm}:{0:ss} ", d1);       ... Read More

DateTime.Compare() Method in C#

AmitDiwan
Updated on 02-Sep-2023 13:40:32

50K+ Views

The DateTime.Compare() method in C# is used for comparison of two DateTime instances. It returns an integer value, 0 − If date1 is later than date2SyntaxFollowing is the syntax −public static int Compare (DateTime d1, DateTime d2);Above, d1 and d2 are the two dates to be compared.ExampleLet us now see an example to implement the DateTime.Compare() method −using System; public class Demo {    public static void Main(){       DateTime d1 = new DateTime(2019, 11, 20, 6, 20, 40);       DateTime d2 = d1.AddYears(5);       Console.WriteLine("Initial DateTime = {0:dd} {0:y}, {0:hh}:{0:mm}:{0:ss} ", d1);   ... Read More

Decimal.Compare() Method in C#

AmitDiwan
Updated on 11-Nov-2019 05:51:42

890 Views

The Decimal.Compare() method in C# is used to compare two specified Decimal values.SyntaxFollowing is the syntax −public static int Compare (decimal val1, decimal val2);Above, val1 is the first value to compare, whereas Val is the second value to compare.The return value is less than zero if val1 is less than val2. Return value is 0, if Val = val2, whereas greater than zero, if val1 is greater than val2.ExampleLet us now see an example to implement the Decimal.Compare() method −using System; public class Demo {    public static void Main(){       Decimal val1 = 45.85m;       ... Read More

Type.GetMembers() Method in C#

AmitDiwan
Updated on 11-Nov-2019 05:50:04

209 Views

The Type.GetMembers() method in C# is used to get the members (properties, methods, fields, events, etc.) of the current Type.SyntaxFollowing is the syntax −public System.Reflection.MemberInfo[] GetMembers (); public abstract System.Reflection.MemberInfo[] GetMembers (System.Reflection.BindingFlags bindingAttr);ExampleLet us now see an example to implement the Type.GetMembers() method −using System; using System.Reflection; public class Demo {    public static void Main(){       Type type = typeof(Subject);       try {          FieldInfo fieldInfo = type.GetField("SubName");          MemberInfo[] info = type.GetMembers();          Console.Write("Members = ");          for (int i = 0; ... Read More

Type.GetMember() Method in C#

AmitDiwan
Updated on 11-Nov-2019 05:47:30

218 Views

The Type.GetMember() method in C# is used to get the specified members of the current Type.SyntaxFollowing is the syntax −public System.Reflection.MemberInfo[] GetMember (string name); public virtual System.Reflection.MemberInfo[] GetMember (string name, System.Reflection.BindingFlags bindingAttr);ExampleLet us now see an example to implement the Type.GetMember() method −using System; using System.Reflection; public class Demo {    public static void Main(){       Type type = typeof(Subject);       try {          FieldInfo fieldInfo = type.GetField("SubName");          MemberInfo[] info = type.GetMember("SubName");          Console.Write("Members = ");          for (int i = 0; i ... Read More

Advertisements