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

226 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

Change Delimiter for Creating a Trigger in MySQL

Swarali Sree
Updated on 22-Jun-2020 12:15:45

595 Views

As we know that in MySQL we use the delimiter semicolon (;) to end each statement. The semicolon is the by default delimiter in MySQL. We need to change the delimiter, while creating a trigger, to tell MySQL that this is not the end of our trigger statement because we can use multiple statements in the trigger. We can change the delimiter temporarily by DELIMITER // statement to change the delimiter from Semicolon (;) to two back-slash (//). After this MySQL would know that the triggering statement only ends when it encounters a two back-slash (//). Following is an example ... Read More

Insert Item in ArrayList in C#

karthikeya Boyini
Updated on 22-Jun-2020 12:14:40

523 Views

To insert an item in an already created ArrayList, use the Insert() method.Firstly, set elements −ArrayList arr = new ArrayList(); arr.Add(45); arr.Add(78); arr.Add(33);Now, let’s say you need to insert an item at 2nd position. For that, use the Insert() method −// inserting element at 2nd position arr.Insert(1, 90);Let us see the complete example −Example Live Demousing System; using System.Collections; namespace Demo {    public class Program {       public static void Main(string[] args) {          ArrayList arr = new ArrayList();          arr.Add(45);          arr.Add(78);       ... Read More

Check Tables of Databases Other Than Current Database

Giri Raju
Updated on 22-Jun-2020 12:14:06

131 Views

With the help of following MySQL command, we can check the tables of a database other than the database we are currently using −Show Tables from Database_name;For example, the following query would display the list of tables from a database named ‘gaurav’ when currently we are using a database named ‘new’ −mysql> use new; Database changed mysql> show tables from gaurav; +--------------------+ | Tables_in_tutorial | +--------------------+ | testing            | | employee           | | tender             | | Ratelist           | +--------------------+ 4 rows in set (0.00 sec)

Instantiate a Class in C#

Samual Sam
Updated on 22-Jun-2020 12:13:46

4K+ Views

Use the new operator to instantiate a class in C#.Let’s say our class is Line. Instantiation will create a new object as shown below −Line line = new Line();Using the object, you can now call the method −line.setLength(6.0);Let us see the example −Example Live Demousing System; namespace LineApplication {    class Line {       private double length; // Length of a line       public Line() {          Console.WriteLine("Object is being created");       }       public void setLength( double len ) {          length = len; ... Read More

Iterate Any Map in C#

karthikeya Boyini
Updated on 22-Jun-2020 12:13:07

2K+ Views

C# has no built-in Math type. For the same, use a Dictionary.Firstly, create a Dictionary −Dictionary d = new Dictionary(); d.Add("keyboard", 1); d.Add("mouse", 2);Get the keys −var val = d.Keys.ToList();Now, use the foreach loop to iterate over the Map −foreach (var key in val) {    Console.WriteLine(key); }To iterate it, try to run the following code −Example Live Demousing System; using System.Collections.Generic; using System.Linq; class Program {    static void Main() {       Dictionary d = new Dictionary();       d.Add("keyboard", 1);       d.Add("mouse", 2);       // get keys   ... Read More

Advertisements