Convert JavaScript Array to Hash Array

Ankith Reddy
Updated on 22-Jun-2020 12:52:47

2K+ Views

Let us say our JavaScript array is −    var myArr = new Array(5);    myArr[0] = "Welcome";    myArr[1] = "to";    myArr[2] = "the";    myArr[3] = "Web";    myArr[4] = "World"; Now, convert the array into a string using comma as a separator −document.getElementById('demo1').value = myArr.join(',');Now, take this to C# −string[] str = demo.Split(",".ToCharArray());The above converts the JavaScript array to C#.

Generating Random Numbers in C#

varun
Updated on 22-Jun-2020 12:51:46

3K+ Views

To generate random numbers, use Random class.Create an object −Random r = new Random();Now, use the Next() method to get random numbers in between a range −r.Next(10,50);The following is the complete code −Example Live Demousing System; public class Program {    public static void Main() {       Random r = new Random();       int genRand= r.Next(10,50);       Console.WriteLine("Random Number = "+genRand);    } }OutputRandom Number = 24

Global and Local Variables in C#

Giri Raju
Updated on 22-Jun-2020 12:51:26

4K+ Views

Local VariablesA local variable is used where the scope of the variable is within the method in which it is declared. They can be used only by statements that are inside that function or block of code.Example Live Demousing System; public class Program {    public static void Main() {       int a;       a = 100;       // local variable       Console.WriteLine("Value:"+a);    } }OutputValue:100Global VariablesC# do not support global variables directly and the scope resolution operator used in C++ for global variables is related to namespaces. It is called global namespace ... Read More

Move Existing MySQL Event to Another Database

Manikanth Mani
Updated on 22-Jun-2020 12:51:23

286 Views

It can be done with the help of ALTER EVENT statement too. We need to use the combination of database name and event name along with the RENAME keyword. To illustrate it we are having the following example in which we are moving the event named ‘hello_renamed’ from ‘query’ database to ‘tutorial’ database −Examplemysql> ALTER EVENT query.hello_renamed RENAME to tutorials.hello_renamed; Query OK, 0 rows affected (0.00 sec)To confirm that event has been moved to database ‘tutorials’ we can try to delete the event with an old name, MySQL will throw an error as follows −mysql> DROP event hello_renamed; ERROR 1539 (HY000): Unknown ... Read More

Simulate MySQL INTERSECT Query

Jennifer Nicholas
Updated on 22-Jun-2020 12:50:41

284 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

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

220 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

79 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

328 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

478 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

Advertisements