Initialize a Tuple to an Empty Tuple in C#

Arjun Thakur
Updated on 22-Jun-2020 12:20:26

3K+ Views

To initialize a tuple to an empty tuple −Tuple myTuple;If you want to check for values in a tuple, that whether it is null or not −Exampleusing System; namespace Demo {    class Program {       static void Main(string[] args) {          Tuple tuple = new Tuple(10, null);          if (tuple.Item1 == 10) {             Console.WriteLine(tuple.Item1);          }          if (tuple.Item2 == null) {             Console.WriteLine("Item is null");          }       }    } }

Enter BOOLEAN Values in MySQL Statement

Anvi Jain
Updated on 22-Jun-2020 12:20:04

492 Views

As we know that there is no BOOLEAN data type in MySQL hence by using TRUE or true, FALSE or false we can enter Boolean values in MySQL statement.Examplemysql> Select TRUE,FALSE; +------+-------+ | TRUE | FALSE | +------+-------+ | 1    | 0     | +------+-------+ 1 row in set (0.00 sec) mysql> Select true,false; +------+-------+ | TRUE | FALSE | +------+-------+ | 1    | 0     | +------+-------+ 1 row in set (0.00 sec)

Get Last 4 Characters from String in C#

radhakrishna
Updated on 22-Jun-2020 12:19:58

3K+ Views

Firstly, set the string −string str = "Football and Tennis";Now, use the substring() method to get the last 4 characters −str.Substring(str.Length - 4);Let us see the complete code −Example Live Demousing System; public class Demo {    public static void Main() {       string str = "Football and Tennis";       string res = str.Substring(str.Length - 4);       Console.WriteLine(res);    } }Outputnnis

MySQL Arithmetic Expression Returns NULL

seetha
Updated on 22-Jun-2020 12:19:41

150 Views

As we know that a NULL is not a value and it is also not the same as zero. MySQL arithmetic expression returns NULL if we will use NULL in it. It can be understood with the help of the following example −Examplemysql> Select 100*NULL; +----------+ | 100*NULL | +----------+ |     NULL | +----------+ 1 row in set (0.00 sec) mysql> Select 100+NULL; +----------+ | 100+NULL | +----------+ |     NULL | +----------+ 1 row in set (0.00 sec)From the above example, it can be observed that if we will use NULL in an arithmetic expression then the result would be NULL itself.

Insert Item in List at Given Position in C#

Chandu yadav
Updated on 22-Jun-2020 12:19:34

3K+ Views

To insert an item in an already created List, use the Insert() method.Firstly, set elements −List list = new List(); list.Add(989); list.Add(345); list.Add(654); list.Add(876); list.Add(234); list.Add(909);Now, let’s say you need to insert an item at 4th position. For that, use the Insert() method −// inserting element at 4th position list.Insert(3, 567);Let us see the complete example −Exampleusing System; using System.Collections.Generic; namespace Demo {    public class Program {       public static void Main(string[] args) {          List < int > list = new List < int > ();         ... Read More

Instantiate Delegates in C#

George John
Updated on 22-Jun-2020 12:17:50

1K+ Views

Use the new keyword to instantiate a delegate. When creating a delegate, the argument passed to the new expression is written similar to a method call, but without the arguments to the method.For example −public delegate void printString(string s); printString ps1 = new printString(WriteToScreen);You can also instantiate a delegate using an anonymous method −//declare delegate void Del(string str); Del d = delegate(string name) {    Console.WriteLine("Notification received for: {0}", name); };Let us see an example that declare and instantiates a delegate −Example Live Demousing System; delegate int NumberChanger(int n); namespace DelegateAppl {    class TestDelegate {     ... Read More

Use MySQL DISTINCT Clause with WHERE and LIMIT Clause

Nikitha N
Updated on 22-Jun-2020 12:17:19

6K+ Views

By using the WHERE clause with a DISTINCT clause in MySQL queries, we are putting a condition on the basis of which MySQL returns the unique rows of the result set. By using the LIMIT clause with a DISTINCT clause in MySQL queries, we are actually providing a perimeter to the server about a maximum number of unique rows of the result set to be returned.ExampleWe can use WHERE and LIMIT clause with DISTINCT as follows on the table named ‘testing’ −mysql> Select * from testing; +------+---------+---------+ | id   | fname   | Lname   | +------+---------+---------+ |  200 ... Read More

Get Records from MySQL Table in a Particular Way

Sreemaha
Updated on 22-Jun-2020 12:16:48

237 Views

For getting the records from MySQL table in the result set in a particular way either ascending or descending, we need to use the ORDER BY clause along with ASC or DESC keywords. If we will not use any of the above-mentioned keywords then MySQL by default return the records in ascending order. The ORDER BY clause returned the result set based on a particular field (ascending or descending order) with which we will use the ORDER BY clause. Suppose we want to sort the rows of the following table −mysql> Select * from Student; +--------+--------+--------+ | Name   | ... Read More

Get Last 2 Characters from String in C# Using Regex

Sreemaha
Updated on 22-Jun-2020 12:16:45

1K+ Views

Set the string −string str = "Cookie and Session";Use the following Regex to get the last 2 characters from string −Regex.Match(str,@"(.{2})\s*$")The following is the code −Example Live Demousing System; using System.Text.RegularExpressions; public class Demo {    public static void Main() {       string str = "Cookie and Session";       Console.WriteLine(Regex.Match(str,@"(.{2})\s*$"));    } }Outputon

Join Two Lists in C#

Ankith Reddy
Updated on 22-Jun-2020 12:16:21

5K+ Views

To join two lists, use AddRange() method.Set the first list −var list1 = new List < string > (); list1.Add("Keyboard"); list1.Add("Mouse");Set the second list −var list2 = new List < string > (); list2.Add("Hard Disk"); list2.Add("Pen Drive");To concatenate both the lists −lists1.AddRange(lists2);The following is the complete code −Exampleusing System.Collections.Generic; using System; namespace Demo {    public static class Program {       public static void Main() {          var list1 = new List < string > ();          list1.Add("Keyboard");          list1.Add("Mouse");          Console.WriteLine("Our list1....");   ... Read More

Advertisements