C# Equivalent to Java Functional Interfaces

mkotla
Updated on 22-Jun-2020 12:50:16

2K+ Views

Equivalent of Java’s Functional Interfaces in C# is Delegates.Let us see the implementation of functional interface in Java −Example@FunctionalInterface public interface MyInterface {    void invoke(); } public class Demo {    void method(){       MyInterface x = () -> MyFunc ();       x.invoke();    }    void MyFunc() {    } }The same implementation in C# delagates −Examplepublic delegate void MyInterface (); public class Demo {    internal virtual void method() {       MyInterface x = () => MyFunc ();       x();    }    internal virtual void MyFunc() {    } }

Simulate MySQL INTERSECT Query with WHERE Clause

Abhinaya
Updated on 22-Jun-2020 12:49:51

229 Views

Since we cannot use INTERSECT query in MySQL, we will use IN operator to simulate the INTERSECT query. It can be understood with the help of the following example −ExampleIn this example, we are two tables namely Student_detail and Student_info having the following data −mysql> Select * from Student_detail; +-----------+---------+------------+------------+ | studentid | Name    | Address    | Subject    | +-----------+---------+------------+------------+ |       101 | YashPal | Amritsar   | History    | |       105 | Gaurav  | Chandigarh | Literature | |       130 | Ram     | Jhansi ... Read More

Different Status Variables in MySQL for Event Counts

Sharon Christine
Updated on 22-Jun-2020 12:49:04

89 Views

Followings are the status variables in MYSQL which provide us the counts of event-related operations −Com_create_event It provides us the number of CREATE EVENT statements executed since the last server restart.Com_alter_event − It provides us the number of ALTER EVENT statements executed since the last server restart.Com_drop_event − It provides us the number of DROP EVENT statements executed since the last server restart.Com_show_create_event − It provides us the number of SHOW CREATE EVENT statements executed since the last server restart.Com_show_events − It provides us the number of SHOW EVENTS statements executed since the last server restart.Read More

C# Equivalent to Java's Double Brace Initialization

usharani
Updated on 22-Jun-2020 12:49:01

340 Views

Java’s Double Brace Initialization does the same work what a single brace can achieve in C#.Double Brace creates and initialize objects in a single Java expression.Let’s say the following is in Java −ExampleList list = new List() {{    add("One");    add("Two");    add("Three");    add("Four"); }}The same you can use for Collection Initializer in C# as −List list = new List() {"One","Two", “Three”, “Four”};

Print First Letter of Each Word in a String Using C# Regex

seetha
Updated on 22-Jun-2020 12:48:42

498 Views

Let’s say our string is −string str = "The Shape of Water got an Oscar Award!";Use the following Regular Expression to display first letter of each word −@"\b[a-zA-Z]"Here is the complete code −Example Live Demousing System; using System.Text.RegularExpressions; namespace RegExApplication {    public class Program {       private static void showMatch(string text, string expr) {          Console.WriteLine("The Expression: " + expr);          MatchCollection mc = Regex.Matches(text, expr);          foreach (Match m in mc) {             Console.WriteLine(m);          }       } ... Read More

Use String.Empty to Initialize a String in C#

karthikeya Boyini
Updated on 22-Jun-2020 12:48:03

655 Views

Set the string as empty using the string.Empty in C# −string myStr = string.Empty;To check whether it is a string or not, use the IsNullOrEmpty() method −if (string.IsNullOrEmpty(myStr)) {    Console.WriteLine("String is empty or null!"); }The following is an example −Example Live Demousing System; namespace Demo {    public class Program {       public static void Main(string[] args) {          string myStr = string.Empty;          if (string.IsNullOrEmpty(myStr)) {             Console.WriteLine("String is empty or null!");          } else {             Console.WriteLine("String isn't empty or null!");          }       }    } }OutputString is empty or null!

Simulate MySQL MINUS Query

mkotla
Updated on 22-Jun-2020 12:47:50

656 Views

Since we cannot use the MINUS query in MySQL, we will use JOIN to simulate the MINUS query. It can be understood with the help of the following example −ExampleIn this example, we are two tables namely Student_detail and Student_info having the following data −mysql> Select * from Student_detail; +-----------+---------+------------+------------+ | studentid | Name    | Address    | Subject    | +-----------+---------+------------+------------+ |       101 | YashPal | Amritsar   | History    | |       105 | Gaurav  | Chandigarh | Literature | |       130 | Ram     | Jhansi ... Read More

Inheritance vs Composition in C#

Samual Sam
Updated on 22-Jun-2020 12:47:31

722 Views

InheritanceWith Inheritance, you can designate that the new class should inherit the members of an existing class. This existing class is called the baseclass, and the new class is referred to as the derived class. Inheritance implements the IS-A relationship. For example, mammal IS A animal, dog IS-A mammal hence dog IS-A animal as well, and so on.For example, A base class Shape has a derived classes like Circle, Square, Rectangle, etc.CompositionUnder Composition, if the parent object is deleted, then the child object also loses its status. Composition is a special type of Aggregation and gives a part-of relationship.For example, ... Read More

Count All MySQL Event Related Operations Collectively

Rama Giri
Updated on 22-Jun-2020 12:46:43

173 Views

With the help of SHOW STATUS statement, we can get the count of MySQL event-related operations. It can be used as follows −mysql> SHOW STATUS LIKE '%event%'; +--------------------------+-------+ | Variable_name            | Value | +--------------------------+-------+ | Com_alter_event          | 16    | | Com_create_event         | 6     | | Com_drop_event           | 4     | | Com_show_binlog_events   | 0     | | Com_show_create_event    | 0     | | Com_show_events          | 4     | | Com_show_relaylog_events | 0     | +--------------------------+-------+ 7 rows in set (0.17 sec)

Local Inner Class in C#

karthikeya Boyini
Updated on 22-Jun-2020 12:46:41

1K+ Views

A nested class is a class declared in another enclosing class and it has inner as well as outer class. It is a member of its enclosing class and the members of an enclosing class have no access to members of a nested classLet us see an example code snippet of nested classes in C#.Here, class Two is a local inner class −Exampleclass One {    public int num1;    public class Two {       public int num2;    } } class Demo {    static void Main() {       One x = new One();   ... Read More

Advertisements