Found 2587 Articles for Csharp

DateTime.ToString() Method in C#

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

431 Views

The DateTime.ToString() method in C# is used to convert the value of the current DateTime object to its equivalent string representation.SyntaxFollowing is the syntax −ToString(String, IFormatProvider) ToString() ToString(IFormatProvider) ToString(String)ExampleLet us now see an example to implement the DateTime.ToString() method −using System; public class Demo {    public static void Main() {       DateTime d = new DateTime(2019, 11, 11, 7, 11, 25);       Console.WriteLine("Date = {0}", d);       string str = d.ToString();       Console.WriteLine("String representation = {0}", str);    } }OutputThis will produce the following output −Date = 11/11/2019 7:11:25 AM String ... Read More

DateTime.ToShortTimeString() Method in C#

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

1K+ Views

The DateTime.ToShortTimeString() method in C# is used to convert the value of the current DateTime object to its equivalent short time string representation.SyntaxFollowing is the syntax −public string ToShortTimeString ();ExampleLet us now see an example to implement the DateTime.ToShortTimeString() method −using System; using System.Globalization; public class Demo {    public static void Main() {       DateTime d = DateTime.Now;       Console.WriteLine("Date = {0}", d);       Console.WriteLine("Current culture = "+CultureInfo.CurrentCulture.Name);       var pattern = CultureInfo.CurrentCulture.DateTimeFormat;       string str = d.ToShortTimeString();       Console.WriteLine("Short time string = {0}", pattern.ShortTimePattern);     ... Read More

Int32.GetHashCode Method in C# with Examples

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

194 Views

The Int32.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 Int32.GetHashCode() method −using System; public class Demo {    public static void Main(){       int val1 = Int32.MinValue;       int val2 = 300;       Console.WriteLine("Value1 = "+val1);       Console.WriteLine("Value2 = "+val2);       Console.WriteLine("Are they equal? = "+val1.Equals(val2));       Console.WriteLine("HashCode for Value1 = "+val1.GetHashCode());       Console.WriteLine("HashCode for Value2 = "+val2.GetHashCode());    } }OutputThis will produce ... Read More

Int32. Equals Method in C# with Examples

AmitDiwan
Updated on 11-Nov-2019 07:35:26

243 Views

The Int32.Equals() method in C# is used to return a value indicating whether this instance is equal to a specified object or Int32.SyntaxFollowing is the syntax −public bool Equals (int ob); public override bool Equals (object ob);Above, the parameter ob in the 1st syntax is an Int32 value to compare to this instance. The 2nd syntax ob parameter is an object to compare to this instance.ExampleLet us now see an example to implement the Int32.Equals() method −using System; public class Demo {    public static void Main(){       int val1 = 299;       int val2 = ... Read More

Type.GetTypeCode() Method in C#

AmitDiwan
Updated on 11-Nov-2019 07:32:38

227 Views

The Type.GetTypeCode() method in C# is used to get the underlying type code of the specified Type.SyntaxFollowing is the syntax −public static TypeCode GetTypeCode (Type type);Above, the type parameter is the type whose underlying type code to get.ExampleLet us now see an example to implement the Type.GetTypeCode() method −using System; public class Demo {    public static void Main(){       Type type1 = typeof(double);       TypeCode type2 = Type.GetTypeCode(type1);       Console.WriteLine("TypeCode = "+type2);    } }OutputThis will produce the following output −TypeCode = DoubleExampleLet us now see another example to implement the Type.GetTypeCode() method ... Read More

Type.GetTypeArray() Method in C#

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

81 Views

The Type.GetTypeArray() method in C# is used to get the types of the objects in the specified array.SyntaxFollowing is the syntax −public static Type[] GetTypeArray (object[] args);The arg argument is an array of objects whose types to determine.ExampleLet us now see an example to implement the Type.GetTypeArray() method −using System; using System.Reflection; public class Demo {    public static void Main(){       Object[] obj = new Object[5];       obj[0] = 10.20;       obj[1] = 20;       obj[2] = 30;       obj[3] = 40;       obj[4] = "tom";   ... Read More

Type.GetProperties() Method in C#

AmitDiwan
Updated on 11-Nov-2019 07:29:46

457 Views

The Type.GetProperties() method in C# is used to get the properties of the current Type.SyntaxFollowing is the syntax −public System.Reflection.PropertyInfo[] GetProperties (); public abstract System.Reflection.PropertyInfo[] GetProperties (System.Reflection.BindingFlags bindingAttr);Above, bindingAttr is a bitwise combination of the enumeration values that specify how the search is performed.Exampleusing System; using System.Reflection; public class Demo {    public static void Main(){       Type type = typeof(System.Type);       PropertyInfo[] info = type.GetProperties();       Console.WriteLine("Properties... ");       for (int i = 0; i < info.Length; i++)          Console.WriteLine(" {0}", info[i].ToString());    } }OutputThis will produce the ... Read More

Boolean.ToString() Method in C#

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

7K+ Views

The Boolean.ToString() method in C# converts the value of this instance to its equivalent string representation (either "True" or "False").SyntaxFollowing is the syntax −public override string ToString ();ExampleLet us now see an example to implement the Boolean.ToString() method −using System; public class Demo {    public static void Main(){       bool b = true;       string res = b.ToString();       Console.WriteLine("Return Value = "+res);    } }OutputThis will produce the following output −Return Value = TrueExampleLet us now see another example to implement the Boolean.ToString() method −using System; public class Demo {    public ... Read More

Boolean.Parse() Method in C#

AmitDiwan
Updated on 24-Apr-2020 11:11:22

1K+ Views

The Boolean.Parse() method in C# is used to convert the specified string representation of a logical value to its Boolean equivalent.SyntaxFollowing is the syntax −public static bool Parse (string val);Above, the parameter value is a string containing the value to convert.ExampleLet us now see an example to implement the Boolean.Parse() method −using System; public class Demo {    public static void Main(){       bool b;       b = bool.Parse("FALSE");       Console.WriteLine("After parsing = "+b);    } }OutputThis will produce the following output −After parsing = FalseExampleLet us see another example −using System; public class ... Read More

Boolean.Equals(Object) Method in C#

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

169 Views

The Boolean.Equals(Object) method in C# returns a value indicating whether this instance is equal to a specified object.SyntaxFollowing is the syntax −public override bool Equals (object ob);Above, ob is an object to compare to this instance.ExampleLet us now see an example to implement the Boolean.Equals(Object) method −using System; public class Demo {    public static void Main(){       bool val1 = true;       object val2 = 5/10;       if (val1.Equals(val2))          Console.WriteLine("Both are equal!");       else          Console.WriteLine("Both aren't equal!");    } }OutputThis will produce the following output −Both aren't equal!

Advertisements