GetHashCode Method in C# CharEnumerator

AmitDiwan
Updated on 04-Nov-2019 11:08:18

73 Views

The CharEnumerator.GetHashCode() method in C# returns a hash code for the current object.Syntaxpublic virtual int GetHashCode ();Let us now see an example to implement the CharEnumerator.GetHashCode() method −Exampleusing System; public class Demo {    public static void Main(){       string strNum = "john";       CharEnumerator ch = strNum.GetEnumerator();       Console.WriteLine("HashCode = "+ch.GetHashCode());       while (ch.MoveNext())          Console.Write(ch.Current + " ");       // disposed       ch.Dispose();       // this will show an error since we disposed the object above       // Console.WriteLine(ch.Current);    } }OutputThis will produce the following output −HashCode = 30571253 j o h n

Dictionary Count Property in C#

AmitDiwan
Updated on 04-Nov-2019 11:05:31

495 Views

The Dictionary. Count property in C# gets the number of key/value pairs in the Dictionary.syntaxpublic int Count { get; }Let us now see an example to implement the Dictionary. Count property −Exampleusing System; using System.Collections.Generic; public class Demo {    public static void Main(){       Dictionary dict =       new Dictionary();       dict.Add("One", "Chris");       dict.Add("Two", "Steve");       dict.Add("Three", "Messi");       dict.Add("Four", "Ryan");       dict.Add("Five", "Nathan");       Console.WriteLine("Count of elements = "+dict.Count);       Console.WriteLine("Key/value pairs...");       foreach(KeyValuePair res in dict){ ... Read More

Return Multiple Results in MySQL Subquery with IN

AmitDiwan
Updated on 04-Nov-2019 10:59:21

368 Views

In MySQL, you can easily return multiple results, but also achieve this with subquery using IN(). Let us first create a table −mysql> create table DemoTable1317 -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> Name varchar(20) -> ); Query OK, 0 rows affected (0.49 sec)Insert some records in the table using insert commandmysql> insert into DemoTable1317(Name) values('Chris Brown'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1317(Name) values('John Doe'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1317(Name) values('Adam Smith'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1317(Name) values('John Smith'); ... Read More

Char.TryParse Method in C#

AmitDiwan
Updated on 04-Nov-2019 10:59:21

468 Views

The Char.TryParse() method in C# is used to convert the value of the specified string to its equivalent Unicode character.Syntaxpublic static bool TryParse (string str, out char res);Let us now see an example to implement the Char.TryParse () method −Exampleusing System; public class Demo {    public static void Main(){       bool res;       Char ch;       res = Char.TryParse("10", out ch);       Console.WriteLine(res);       Console.WriteLine(ch.ToString());    } }OutputThis will produce the following output −FalseLet us now see another example −Exampleusing System; public class Demo {    public static void ... Read More

Char.ToUpperInvariant Method in C#

AmitDiwan
Updated on 04-Nov-2019 10:57:49

221 Views

The Char.ToUpperInvariant() method in C# is used to convert the value of a Unicode character to its uppercase equivalent using the casing rules of the invariant culture.Syntaxpublic static char ToUpperInvariant (char ch);Above, the parameter ch is the Unicode character to convert.Let us now see an example to implement the Char.ToUpperInvariant() method −Exampleusing System; public class Demo {    public static void Main(){       char ch = 'q';       char res = Char.ToUpperInvariant(ch);       Console.WriteLine("Value = "+ch);       Console.WriteLine("Uppercase Equivalent = "+res);    } }OutputThis will produce the following output −Value = q ... Read More

Select Words from Text in a MySQL Table

AmitDiwan
Updated on 04-Nov-2019 10:56:56

302 Views

Let us first create a table −mysql> create table DemoTable1316 -> ( -> Value varchar(40) -> ); Query OK, 0 rows affected (0.47 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1316 values('MySQL'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1316 values('Java'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1316 values('MongoDB'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable1316 values('C++'); Query OK, 1 row affected (0.13 sec)Display all records from the table using select statement −mysql> select *from DemoTable1316;This will produce the following output. These are the ... Read More

Log10 Method in C#

AmitDiwan
Updated on 04-Nov-2019 10:55:43

388 Views

The Math.Log10() method in C# is returned to the base 10 logarithms of a specified number.Syntaxpublic static double Log10 (double val);Here, Val is the number whose logarithm we want.The Log10() method returns −Val parameterReturnsPositiveThe base 10 log of d; that is, log 10d.ZeroNegativeInfinityNegativeNaNEqual to NaNNaNEqual to PositiveInfinityPositiveInfinityLet us now see an example to implement Math.Log10() method −Exampleusing System; public class Demo {    public static void Main(){       double val1 = Double.PositiveInfinity; ;       double val2 = Double.NegativeInfinity;       Console.WriteLine(Math.Log10(val1));       Console.WriteLine(Math.Log10(val2));    } }OutputThis will produce the following output −∞ NaNLet ... Read More

Convert Empty Values to NULL in MySQL Query

AmitDiwan
Updated on 04-Nov-2019 10:55:35

1K+ Views

It’s easy to convert empty values to NULL using SET and WHERE. Let us first create a table −mysql> create table DemoTable1315 -> ( -> CountryName varchar(10) -> ); Query OK, 0 rows affected (0.60 sec)Insert some records in the table using insert command. We have set some empty values here as well −mysql> insert into DemoTable1315 values('US'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1315 values(''); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable1315 values('UK'); Query OK, 1 row affected (0.70 sec) mysql> insert into DemoTable1315 values(''); Query OK, 1 row affected (0.12 ... Read More

Math Log Method in C#

AmitDiwan
Updated on 04-Nov-2019 10:52:30

1K+ Views

The Math.Log() method in C# is used to return the logarithm of a specified number.Syntaxpublic static double Log(double num) public static double Log(double num, double base)Above, num is the specified number whose logarithm is to be calculated. Here, the base is the base of the logarithm.Let us now see an example to implement the Math.Log() method −Exampleusing System; public class Demo {    public static void Main(){       double val1 = 2.15;       double val2 = -2.15;       Console.WriteLine(Math.Log(val1));       Console.WriteLine(Math.Log(val2));    } }OutputThis will produce the following output −0.765467842139571 NaNExampleLet us ... Read More

MySQL Query to Display Records Ordered by Numeric Difference

AmitDiwan
Updated on 04-Nov-2019 10:46:31

92 Views

Use ORDER BY and set the difference to display records ordered by numeric difference. Following is the syntax −select *from yourTableName order by (yourIntegerColumnName1 - yourIntegerColumnName2);Let us first create a table −mysql> create table DemoTable1313 -> ( -> Name varchar(20), -> Score1 int, -> Score2 int -> ); Query OK, 0 rows affected (3.48 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1313 values('Chris', 40, 60); Query OK, 1 row affected (0.38 sec) mysql> insert into DemoTable1313 values('David', 70, 50); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1313 values('Adam', 35, 30); Query OK, ... Read More

Advertisements