Programming Articles - Page 2343 of 3366

Convert.ToBase64CharArray() Method in C#

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

281 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

68 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

How to convert a Map to JSON object using JSON-lib API in Java?

raja
Updated on 08-Jul-2020 08:20:25

6K+ Views

A JSONObject is an unordered collection of name/value pairs whereas Map is an object that maps keys to values. A Map cannot contain duplicate keys and each key can map to at most one value. We need to use the JSON-lib library for serializing and de-serializing a Map in JSON format. Initially, we can create a POJO class and pass this instance as an argument to the put() method of Map class and finally add this map instance to the accumulateAll() method of JSONObject.Syntaxpublic void accumulateAll(Map map)In the below example, we can convert Map to a JSON object.Exampleimport java.util.*; import net.sf.json.JSONObject; public class ConvertMapToJSONObjectTest { ... Read More

Tuple Class in C#

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

149 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

132 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

276 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

Math.Truncate() Method in C#

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

609 Views

The Math.Truncate() method in C# is used to compute an integral part of a number, which is Double or Decimal.Syntaxpublic static decimal Truncate(decimal val1) public static double Truncate(double val2)Above, there are two syntaxes. The value val1 is the decimal number to truncate, whereas val2 is the double number to truncate.ExampleLet us now see an example to implement Math.Truncate() method −using System; public class Demo {    public static void Main(){       Decimal val1 = 25.46467m;       Decimal val2 = 45.9989m;       Decimal val3 = 678.325m;       Console.WriteLine(Math.Truncate(val1));       Console.WriteLine(Math.Truncate(val2));   ... Read More

Math.Tanh() Method in C#

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

117 Views

The Math.Tanh() method in C# is used to return the hyperbolic tangent of the specified angle.Syntaxpublic static double Tanh (double val);Above, Val is the angle.ExampleLet us now see an example to implement Math.Tanh() method −using System; public class Demo {    public static void Main(){       double val1 = 30.0;       double val2 = (60 * (Math.PI)) / 180;       Console.WriteLine(Math.Tanh(val1));       Console.WriteLine(Math.Tanh(val2));    } }OutputThis will produce the following output −1 0.780714435359268ExampleLet us see another example to implement Math.Tanh() method −using System; public class Demo {    public static void Main(){ ... Read More

CharEnumerator.Reset() Method in C#

AmitDiwan
Updated on 05-Nov-2019 06:58:50

119 Views

The CharEnumerator.Reset() method in C# initializes the index to a position logically before the first character of the enumerated string.Syntaxpublic void Reset ();ExampleLet us now see an example to implement the CharEnumerator.Reset() 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());       while (ch.MoveNext())          Console.Write(ch.Current + " ");       ch.Reset();       Console.WriteLine();       while (ch.MoveNext()) ... Read More

Advertisements