Found 2628 Articles for Csharp

Decimal.ToOACurrency() Method in C#

AmitDiwan
Updated on 06-Nov-2019 07:59:34

35 Views

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

Type.GetHashCode() Method in C#

AmitDiwan
Updated on 06-Nov-2019 07:15:11

66 Views

The Type.GetHashCode() method in C# is used to return the hash code for this instance.SyntaxFollowing is the syntax −public override int GetHashCode ();ExampleLet us now see an example to implement the Type.GetHashCode() method −using System; public class Demo {    public static void Main(){       string[] arr = {"tom", "amit", "kevin", "katie"};       Type t1 = arr.GetType();       Type t2 = t1.GetElementType();       Console.WriteLine("Type = "+t2.ToString());       Console.WriteLine("Hash Code = "+t1.GetHashCode());    } }OutputThis will produce the following output −Type = System.String Hash Code = 9144789ExampleLet us now see another ... Read More

Type.GetField() Method in C#

AmitDiwan
Updated on 06-Nov-2019 07:12:54

245 Views

The Type.GetField() method in C# is used to get a specific field of the current Type.SyntaxFollowing is the syntax −public System.Reflection.FieldInfo GetField (string name); public abstract System.Reflection.FieldInfo GetField (string name, System.Reflection.BindingFlags bindingAttr);Above, the name is the string containing the name of the data field to get. The bindingAttr parameter is the bitwise combination of the enumeration values that specify how the search is conducted.ExampleLet us now see an example to implement the Type.GetField() method −using System; using System.Reflection; public class Demo {    public static void Main(){       Type type = typeof(Subject);       try {   ... Read More

Type.GetEnumValues() Method in C#

AmitDiwan
Updated on 06-Nov-2019 07:10:29

220 Views

The Type.GetEnumValues() method in C# returns an array of the values of the constants in the current enumeration type.SyntaxFollowing is the syntax −public virtual Array GetEnumValues ();ExampleLet us now see an example to implement the Type.GetEnumValues() method −using System; public class Demo {    enum Vehicle {Car, Bus, Bike, Airplane}    public static void Main(){       try {          Type type = typeof(int);          string[] str = type.GetEnumNames();          Console.WriteLine("GetEnumNames() to return the constant name = " + str);          Type type2 = type.GetEnumUnderlyingType();     ... Read More

Type.GetEnumUnderlyingType() Method in C#

AmitDiwan
Updated on 06-Nov-2019 07:07:27

47 Views

The Type.GetEnumUnderlyingType() method in C# is used to return the underlying type of the current enumeration type.SyntaxFollowing is the syntax −public virtual Type GetEnumUnderlyingType ();ExampleLet us now see an example to implement the Type.GetEnumUnderlyingType() method −using System; public class Demo {    enum Vehicle {Car, Bus, Bike, Airplane}    public static void Main(){       try {          Vehicle v = Vehicle.Bike;          Type type = v.GetType();          string[] str = type.GetEnumNames();          Console.WriteLine("GetEnumName() to return the constant name = " + str);         ... Read More

Type.GetEnumNames() Method in C#

AmitDiwan
Updated on 06-Nov-2019 07:03:50

45 Views

The Type.GetEnumNames() method in C# is used to return the names of the members of the current enumeration type.SyntaxFollowing is the syntax −public virtual string[] GetEnumNames ();ExampleLet us now see an example to implement the Type.GetEnumNames() method −using System; public class Demo {    enum Vehicle {Car, Bus, Bike}    public static void Main(){       try {          Type type = typeof(string);          string[] str = type.GetEnumNames();          Console.WriteLine("GetEnumName() to return the constant name = " + str);          Console.WriteLine("Listing constants ..");         ... Read More

How to create 1-Tuple or Singleton Tuple in C#?

AmitDiwan
Updated on 06-Nov-2019 06:59:07

90 Views

The Tuple class represents a 1-tuple, which is called singleton. A tuple is a data structure that has a sequence of elements.ExampleLet us now see an example to implement the 1-tuple in C# −using System; public class Demo {    public static void Main(string[] args) {       Tuple tuple = new Tuple(100);       Console.WriteLine("Value = " + tuple.Item1);       if (tuple.Item1 == 150) {          Console.WriteLine(tuple.Item1);       }       if (tuple.Item1 == 100) {          Console.WriteLine(tuple.Item1);       }    } }OutputThis will ... Read More

DateTimeOffset.FromUnixTimeSeconds() Method in C#

AmitDiwan
Updated on 06-Nov-2019 06:56:10

682 Views

The DateTimeOffset.FromUnixTimeSeconds() method in C# is used to convert a Unix time expressed as the number of seconds that have elapsed since 1970-01-01T00:00:00Z to a DateTimeOffset value.SyntaxFollowing is the syntax −public static DateTimeOffset FromUnixTimeSeconds (long val);Above, the parameter value is a Unix time, expressed as the number of seconds that have elapsed since 1970-01-01T00:00:00Z (January 1, 1970, at 12:00 AM UTC).ExampleLet us now see an example to implement the DateTimeOffset.FromUnixTimeSeconds() method −using System; public class Demo {    public static void Main() {       DateTimeOffset offset = DateTimeOffset.FromUnixTimeSeconds(20);       Console.WriteLine("DateTimeOffset = {0} ", offset);     ... Read More

DateTimeOffset.FromUnixTimeMilliseconds() Method in C#

AmitDiwan
Updated on 06-Nov-2019 06:54:05

1K+ Views

The DateTimeOffset.FromUnixTimeMilliseconds() method in C# is used to convert a Unix time expressed as the number of milliseconds that have elapsed since 1970-01-01T00:00:00Z to a DateTimeOffset value.SyntaxFollowing is the syntax −public static DateTimeOffset FromUnixTimeMilliseconds (long val);Above, Val are the milliseconds that have elapsed since 1970-01-01T00:00:00Z (January 1, 1970, at 12:00 AM UTC).ExampleLet us now see an example to implement the DateTimeOffset.FromUnixTimeMilliseconds() method −using System; public class Demo {    public static void Main() {       DateTimeOffset offset = DateTimeOffset.FromUnixTimeMilliseconds(30000);       Console.WriteLine("DateTimeOffset = {0} ", offset);       Console.WriteLine("DateTimeOffset (other format) = {0:dd} {0:y}, {0:hh}:{0:mm}:{0:ss} ", ... Read More

DateTimeOffset.FromFileTime() Method in C#

AmitDiwan
Updated on 21-Apr-2020 10:58:38

33 Views

The DateTimeOffset.FromFileTime() method in C# is used to convert the specified Windows file time to an equivalent local time.SyntaxFollowing is the syntax −public static DateTimeOffset FromFileTime (long time);Above, time is the Windows file time, in ticks.ExampleLet us now see an example to implement the DateTimeOffset.FromFileTime() method −using System; public class Demo {    public static void Main() {       DateTimeOffset offset = DateTimeOffset.FromFileTime(0);       Console.WriteLine("DateTimeOffset = {0:dd} {0:y}, {0:hh}:{0:mm}:{0:ss} ", offset);    } }OutputThis will produce the following output −DateTimeOffset = 01 January 1601, 12:00:00ExampleLet us now see another example to implement the DateTimeOffset.FromFileTime() method −using ... Read More

Advertisements