Programming Articles - Page 2323 of 3366

How to create 5-Tuple or quintuple in C#?

AmitDiwan
Updated on 12-Nov-2019 07:50:32

139 Views

The Tuple class represents a 5-tuple, which is called quintuple. A tuple is a data structure that has a sequence of elements.It has five 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.Item4 − Get the value of the current Tuple object's fourth component.Item5 − Get the value of the current Tuple object's fifth component.ExampleLet us now see an example to implement the 5-tuple in C# −using System; public class Demo {    public static void Main(string[] args) { ... Read More

DateTimeOffset.AddTicks() Method in C#

AmitDiwan
Updated on 12-Nov-2019 07:46:39

200 Views

The DateTimeOffset.AddTicks() method in C# is used to add a specified number of ticks to the value of this instance.SyntaxFollowing is the syntax −public DateTimeOffset AddTicks (long val);Above, the Val is the ticks, which is a number of 100-nanosecond ticks. To subtract ticks, set a negative value.Let us see the number of ticks value −Time intervalNumber of ticksSecond10, 000, 000Minute600, 000, 000Hour36, 000, 000, 000Day864, 000, 000, 000Week6, 048, 000, 000, 000MonthIt depends on the number of days in the month.Non-leap year315, 360, 000, 000, 000Leap year316, 224, 000, 000, 000ExampleLet us now see an example to implement the DateTimeOffset.AddTicks() ... Read More

Dictionary.Remove() Method in C#

AmitDiwan
Updated on 12-Nov-2019 07:43:25

7K+ Views

The Dictionary.Remove() property in C# is used to remove the value with the specified key from the Dictionary.SyntaxFollowing is the syntax −public bool Remove (TKey key);Above, the key is the key to remove.ExampleLet us now see an example to implement the Dictionary.Remove() property −using System; using System.Collections.Generic; public class Demo {    public static void Main(){       Dictionary dict =       new Dictionary();       dict.Add("One", "Kagido");       dict.Add("Two", "Ngidi");       dict.Add("Three", "Devillers");       dict.Add("Four", "Smith");       dict.Add("Five", "Warner");       Console.WriteLine("Count of elements = "+dict.Count); ... Read More

Dictionary.Keys Property in C#

AmitDiwan
Updated on 12-Nov-2019 07:39:00

324 Views

The Dictionary.Keys property in C# is used to fetch all the keys in the Dictionary.SyntaxFollowing is the syntax −public System.Collections.Generic.Dictionary.KeyCollection Keys { get; }ExampleLet us now see an example to implement the Dictionary.Keys property −using System; using System.Collections.Generic; public class Demo {    public static void Main(){       Dictionary dict =       new Dictionary();       dict.Add("One", "Kagido");       dict.Add("Two", "Ngidi");       dict.Add("Three", "Devillers");       dict.Add("Four", "Smith");       dict.Add("Five", "Warner");       Console.WriteLine("Count of elements = "+dict.Count);       Console.WriteLine("Key/value pairs...");       foreach(KeyValuePair ... Read More

Dictionary.Item[] Property in C#

AmitDiwan
Updated on 12-Nov-2019 07:35:43

463 Views

The Dictionary.Item[] property in C# is used to get or set the value associated with the specified key in the Dictionary.SyntaxFollowing is the syntax −public TValue this[TKey key] { get; set; }ExampleLet us now see an example to implement the Dictionary.Item[] property −using System; using System.Collections.Generic; public class Demo {    public static void Main(){       Dictionary dict =       new Dictionary();       dict.Add("One", "Chris");       dict.Add("Two", "Steve");       dict.Add("Three", "Messi");       dict.Add("Four", "Ryan");       dict.Add("Five", "Nathan");       Console.WriteLine("Count of elements = "+dict.Count);   ... Read More

Dictionary.Add() Method in C#

AmitDiwan
Updated on 12-Nov-2019 07:32:48

295 Views

The Dictionary.Add() method in C# is used to add a specified key and value to the dictionary.SyntaxFollowing is the syntax −public void Add (TKey key, TValue val);Above, the key parameter is the key, whereas Val is the value of the element.ExampleLet us now see an example to implement the Dictionary.Add() method −using System; using System.Collections.Generic; public class Demo {    public static void Main(){       Dictionary dict =       new Dictionary();       dict.Add("One", "John");       dict.Add("Two", "Tom");       dict.Add("Three", "Jacob");       dict.Add("Four", "Kevin");       dict.Add("Five", "Nathan"); ... Read More

DateTimeOffset.AddSeconds() Method in C#

AmitDiwan
Updated on 12-Nov-2019 07:29:25

338 Views

The DateTimeOffset.AddSeconds() method in C# is used to return a new DateTimeOffset object that adds a specified number of whole and fractional seconds to the value of this instance.SyntaxFollowing is the syntax −public DateTimeOffset AddSeconds (double val);Above, Val is the number of seconds to be added. To subtract seconds, set a negative value.ExampleLet us now see an example to implement the DateTimeOffset.AddSeconds() method −using System; public class Demo {    public static void Main() {       DateTimeOffset dateTimeOffset = new DateTimeOffset(2019, 10, 11, 7, 10, 20, new TimeSpan(-5, 0, 0));       Console.WriteLine("DateTimeOffset (before adding seconds) = ... Read More

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

raja
Updated on 08-Jul-2020 12:53:38

2K+ Views

The JSONArray is a sequence of values, the external text is a string enclosed in square brackets with commas separating the values and internal text is an object having get() and opt() methods, we need to access those values by index. The element() method for adding or replacing those values. An array is an object that stores multiple values of the same type. It can hold both primitive types and object references. We can convert a JSON array to array by using the toArray() method of JSONArray class. This method produces an Object[] with the contents of JSONArray.Syntaxpublic Object[] toArray()Exampleimport java.util.Arrays; import net.sf.json.JSONArray; public ... Read More

How can we use @Since annotation using Gson in Java?

raja
Updated on 08-Jul-2020 12:38:47

451 Views

The @Since annotation can use with the setVersion() method of the GsonBuilder class. This annotation can apply to a field in java class and accepts float as an argument. This argument represents the version number in which the field has serialized. The same can apply to the deserialization process.Syntax@Documented @Retention(value=RUNTIME) @Target(value={FIELD, TYPE}) public @interface SinceExampleimport com.google.gson.annotations.Since; import com.google.gson.Gson; import com.google.gson.GsonBuilder; public class GsonSinceAnnotationTest {    public static void main(String[] args) {       Employee emp = new Employee();       emp.setEmployeeName("Raja Ramesh");       emp.setEmployeeId(125);       emp.setEmployeeTechnology("Java");       emp.setEmploeeAddress("Hyderabad");       System.out.println("Since version ... Read More

DateTimeOffset.AddMonths() Method in C#

AmitDiwan
Updated on 11-Nov-2019 07:48:50

355 Views

The DateTimeOffset.AddMonths() method in C# is used to add a specified number of months to the value of this instance.SyntaxFollowing is the syntax −public DateTimeOffset AddMonths (int val);Above, Val is the number of months to be added. For subtracting months, set a negative value.ExampleLet us now see an example to implement the DateTimeOffset.AddMonths() method −using System; public class Demo {    public static void Main() {       DateTimeOffset dateTimeOffset = new DateTimeOffset(2019, 08, 10, 4, 20, 10, new TimeSpan(-5, 0, 0));       Console.WriteLine("DateTimeOffset (before adding months) = {0}", dateTimeOffset);       DateTimeOffset res = dateTimeOffset.AddMonths(3); ... Read More

Advertisements