Found 2587 Articles for Csharp

MathF.Truncate() Method in C# with Examples

AmitDiwan
Updated on 05-Nov-2019 07:47:44

380 Views

The MathF.Truncate() method in C# is used to calculate an integral part of a specified single number or single-precision floating-point number.SyntaxFollowing is the syntax −public static float Truncate (float val);Above, Val is the specified number to be truncatedExampleLet us now see an example to implement the MathF.Truncate() method −using System; public class Demo {    public static void Main(){       float val1 = float.PositiveInfinity;       float val2 = float.NegativeInfinity;       Console.WriteLine("MathF.Truncate(val1) = "+MathF.Truncate(val1));       Console.WriteLine("MathF.Truncate(val2) = "+MathF.Truncate(val2));    } }OutputThis will produce the following output −MathF.Truncate(val1) = Infinity MathF.Truncate(val2) = -InfinityExampleLet us ... Read More

MathF.Tanh() Method in C# with Examples

AmitDiwan
Updated on 05-Nov-2019 07:44:22

130 Views

The MathF.Tanh() method in C# returns the hyperbolic tangent of a given single value argument.SyntaxFollowing is the syntax −public static float Tanh (float val);Above, Val is the is number whose hyperbolic tangent is to be returned.ExampleLet us now see an example to implement the MathF.Tanh() method −using System; public class Demo {    public static void Main(){       float val1 = 10f;       float val2 = float.NaN;       Console.WriteLine("MathF.Tanh(val1) = "+MathF.Tanh(val1));       Console.WriteLine("MathF.Tanh(val2) = "+MathF.Tanh(val2));    } }OutputThis will produce the following output −MathF.Tanh(val1) = 1 MathF.Tanh(val2) = NaNExampleLet us now see ... Read More

MathF.Tan() Method in C# with Examples

AmitDiwan
Updated on 05-Nov-2019 07:42:02

161 Views

The MathF.Tan() method in C# is used to return the tangent of a given float value argument.SyntaxFollowing is the syntax −public static float Tan (float val);Above, Val is the angle whose tangent is to be returned.ExampleLet us now see an example to implement the MathF.Tan() method −using System; public class Demo {    public static void Main(){       float val1 = 10f;       float val2 = float.NaN;       Console.WriteLine("MathF.Tan(val1) = "+MathF.Tan(val1));       Console.WriteLine("MathF.Tan(val2) = "+MathF.Tan(val2));    } }OutputThis will produce the following output −MathF.Tan(val1) = 0.6483608 MathF.Tan(val2) = NaNExampleLet us now see ... Read More

Convert.ToBase64String() Method in C#

AmitDiwan
Updated on 05-Nov-2019 07:37:58

1K+ Views

The Convert.ToBase64String() method in C# is used to convert the value of an array of 8-bit unsigned integers to its equivalent string representation that is encoded with base-64 digits.SyntaxFollowing is the syntax −public static string ToBase64String (byte[] arr);Above, arr is an array of 8-bit unsigned integers.ExampleLet us now see an example to implement the Convert.ToBase64String() method −Using System; public class Demo {    public static void Main(){       byte[] val1 = {5, 10, 15, 20, 25, 30};       string str = Convert.ToBase64String(val1);       Console.WriteLine("Base 64 string: '{0}'", str);       byte[] val2 = ... Read More

Convert.ToBase64CharArray() Method in C#

AmitDiwan
Updated on 05-Nov-2019 07:36:26

276 Views

The Convert.ToBase64CharArray() method in C# is used to convert a subset of an 8-bit unsigned integer array to an equivalent subset of a Unicode character array encoded with base-64 digits.SyntaxFollowing is the syntax −public static int ToBase64CharArray (byte[] arr, int offsetIn, int length, char[] outArray, int offsetOut);Here, arr − An input array of 8-bit unsigned integers.offsetIn − A position within arr.length − The number of elements of arr to convert.outArray − An output array of Unicode characters.offsetOut − A position within outArray.ExampleLet us now see an example to implement the Convert.ToBase64CharArray() method −using System; public class Demo {    public ... Read More

Convert.FromBase64String(String) Method in C#

AmitDiwan
Updated on 05-Nov-2019 07:23:41

3K+ Views

The Convert.FromBase64String(String) method in C# converts the specified string, which encodes binary data as base-64 digits, to an equivalent 8-bit unsigned integer array.SyntaxFollowing is the syntax −public static byte[] FromBase64String (string str);Above, the parameter str is the string to convert.ExampleLet us now see an example to implement the Convert.FromBase64String(String) method −using System; public class Demo {    public static void Main(){       byte[] val1 = {5, 10, 15, 20, 25, 30};       string str = Convert.ToBase64String(val1);       Console.WriteLine("Base 64 string: '{0}'", str);       byte[] val2 = Convert.FromBase64String(str);       Console.WriteLine("Converted byte ... Read More

CharEnumerator.ToString() Method in C#

AmitDiwan
Updated on 05-Nov-2019 07:20:36

63 Views

The CharEnumerator.ToString() method in C# gets a string that represents the current object.SyntaxFollowing is the syntax -public virtual string ToString();ExampleLet us now see an example to implement the CharEnumerator.ToString() method −using System; public class Demo {    public static void Main(){       string strNum = "This is it!";       CharEnumerator ch = strNum.GetEnumerator();       Console.WriteLine("HashCode = "+ch.GetHashCode());       Console.WriteLine("Get the Type = "+ch.GetType());       Console.WriteLine("String representation = "+ch.ToString());       while (ch.MoveNext())          Console.Write(ch.Current + " ");       ch.Reset();       Console.WriteLine();   ... Read More

Tuple Class in C#

AmitDiwan
Updated on 05-Nov-2019 07:17:27

141 Views

The Tuple class represents a 3-tuple, which is called triple. A tuple is a data structure that has a sequence of elements.It is used in −Easier access to a data set.Easier manipulation of a data set.To represent a single set of data.To return multiple values from a methodTo pass multiple values to a methodIt has three properties −Item1 − Get the value of the current Tuple object's first component.Item2 −Get the value of the current Tuple object's second component.Item3 − Get the value of the current Tuple object's third component.ExampleLet us now see an example to implement the 3-tuple in C# ... Read More

Tuple Class in C#

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

117 Views

The Tuple class represents a 1-tuple, which is called singleton. A tuple is a data structure that has a sequence of elements.It is used in −Easier access to a data set.Easier manipulation of a data set.To represent a single set of data.To return multiple values from a methodTo pass multiple values to a methodIt has one property −Item1 − Get the value of the current Tuple object's first component.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 ... Read More

Tuple Class in C#

AmitDiwan
Updated on 05-Nov-2019 07:08:31

265 Views

If you want to return more than one value from a class method, then use C# Tuples. To create tuples in C#< this class provides a static method. Tuples introduced in .NET 4.0.ExampleLet us now see an example to implement Tuple in C# −using System; public class Demo {    public static void Main(string[] args) {       Tuple tuple = new Tuple(2, "Tom");       if (tuple.Item1 == 150) {          Console.WriteLine(tuple.Item1);       }       if (tuple.Item2 == "Tom") {          Console.WriteLine(tuple.Item2);       }    } }OutputThis will produce the following output −Tom

Advertisements