Arjun Thakur has Published 1025 Articles

Sort KeyValuePairs in C#

Arjun Thakur

Arjun Thakur

Updated on 22-Jun-2020 14:28:04

868 Views

Use the Sort method to sort the KeyValuePairs collection.Firstly, set the collection −var myList = new List(); // adding elements myList.Add(new KeyValuePair(1, 20)); myList.Add(new KeyValuePair(2, 15)); myList.Add(new KeyValuePair(3, 35)); myList.Add(new KeyValuePair(4, 50)); myList.Add(new KeyValuePair(5, 25));To sort, use the Sort() method. With that, we have used the CompareTo() method to ... Read More

How can we create MySQL view by selecting data based on pattern matching from base table?

Arjun Thakur

Arjun Thakur

Updated on 22-Jun-2020 14:19:38

178 Views

MySQL LIKE operator is used to select data based on pattern matching. Similarly, we can use LIKE operator with views to select particular data based on pattern matching from the base table. To understand this concept we are using the base table ‘student_info’ having the following data −mysql> Select * from Student_info; ... Read More

C# Program to get the difference between two dates

Arjun Thakur

Arjun Thakur

Updated on 22-Jun-2020 14:18:30

3K+ Views

Use DateTime.Subtract to get the difference between two dates in C#.Firstly, set two dates −DateTime date1 = new DateTime(2018, 8, 27); DateTime date2 = new DateTime(2018, 8, 28);Use the Subtract method to get the difference −TimeSpan t = date2.Subtract(date1);The following is the complete code −Example Live Demousing System; using System.Threading; using ... Read More

Convert string to bool in C#

Arjun Thakur

Arjun Thakur

Updated on 22-Jun-2020 14:15:52

2K+ Views

To convert a string to a bool, use the Bool.parse method in C# −Firstly, set a string −string str = "false";Now, convert it to bool −bool.Parse(str);Here is the complete code −Example Live Demousing System; using System.Linq; class Demo {    static void Main() {       string str = "false"; ... Read More

C# Program to display the number of days in a month

Arjun Thakur

Arjun Thakur

Updated on 22-Jun-2020 14:12:25

728 Views

Use the DaysInMonth to display the number of days in a month.Add the year and month as a parameter for the DaysInMonth() method −DateTime.DaysInMonth(2018, 8);The following is an example −Example Live Demousing System; using System.Collections.Generic; using System.Linq; public class Demo {    public static void Main() {       Console.WriteLine("Today ... Read More

Represent exact representation of no time in C#

Arjun Thakur

Arjun Thakur

Updated on 22-Jun-2020 14:10:56

99 Views

Use the TimeSpan.Zero to represent the exact representation of no time i.e −00:00:00Set an object for TimeSpan −TimeSpan ts;Now, the TimeSpan.Zero is used to display no time −TimeSpan ts = TimeSpan.Zero;Example Live Demousing System; using System.Linq; public class Demo {    public static void Main() {       TimeSpan ts ... Read More

Enum.GetNames in C#

Arjun Thakur

Arjun Thakur

Updated on 22-Jun-2020 13:57:05

52 Views

It gets an array of the names of constants in an enumeration. The following is the syntax −Enum.GetNames(Type)Here, Type is an enumeration type.The following is an example −Example Live Demousing System; class Demo {    enum Vehicle {       Car,       Motorbike,       Truck, ... Read More

Buffer Type in C#

Arjun Thakur

Arjun Thakur

Updated on 22-Jun-2020 13:54:56

697 Views

To handle range of bytes, use Buffer Type in C#. Its method Buffer.BlockCopy copies the bytes from one byte array to another byte array.Example Live Demousing System; class Demo {    static void Main() {       // byte arrays       byte[] b1 = new byte[] {39, 45, ... Read More

Buffer GetByte Example in C#

Arjun Thakur

Arjun Thakur

Updated on 22-Jun-2020 13:52:38

234 Views

Read individual bytes using GetByte() method in C# −Set an array −int[] arr = { 3, 4, 12 };Now, use Buffer.GetByte() to display the array elements and to read individual bytes −for (int i = 0; i < Buffer.ByteLength(arr); i++) {    Console.WriteLine(Buffer.GetByte(arr, i)); }The following is the code −Example Live ... Read More

C# program to join words into a string in C#

Arjun Thakur

Arjun Thakur

Updated on 22-Jun-2020 13:50:17

259 Views

Declare a string and add elements −string[] str = { "One", "Two", "Three", "Four", "Five" };Use the Join() method to join the words−string res = string.Join(" ", str);Let us see the complete code −Example Live Demousing System; public class Demo {    public static void Main() {       ... Read More

Advertisements