To set the timer information to zero, use the Stopwatch Restart method.Firstly, begin the Stopwatch −Stopwatch s = Stopwatch.StartNew();Then, use Restart() to set the timer to zero −s.Restart();Let us see the complete code −ExampleLive Demousing System; using System.Threading; using System.Diagnostics; public class Demo { public static void Main() { Stopwatch s = Stopwatch.StartNew(); Thread.Sleep(500); // restart s.Restart(); // begin again Thread.Sleep(500); Console.WriteLine(s.Elapsed); } }Output00:00:00.5004937
Use DateTime.Subtract to get the difference between two dates in C#.Firstly, set two dates −DateTime date1 = new DateTime(2018, 8, 27); DateTime date2 = new DateTime(2018, 8, 28);Use the Subtract method to get the difference −TimeSpan t = date2.Subtract(date1);The following is the complete code −Example Live Demousing System; using System.Threading; using System.Diagnostics; public class Demo { public static void Main() { DateTime date1 = new DateTime(2018, 8, 27); DateTime date2 = new DateTime(2018, 8, 28); // getting the difference TimeSpan t = date2.Subtract(date1); Console.WriteLine(t); Console.WriteLine("Days (Difference) = {0} ", t.TotalDays); Console.WriteLine("Minutes (Difference) = {0}", t.TotalMinutes); } }Output1.00:00:00 Days (Difference) = 1 Minutes (Difference) = 1440
We can use the similar syntax of the ORDER BY clause into the PHP function – mysql_query(). This function is used to execute the SQL command and later another PHP function – mysql_fetch_array() can be used to fetch all the selected data.To illustrate it we are having the following example −ExampleIn this example, we are writing a PHP script that will return the result in descending order of the authors of the tutorial −
Set a DateTime object;DateTime dt = DateTime.Now;To get years in different formats, try the following −dt.ToString("yy") dt.ToString("yyy") dt.ToString("yyyy") dt.ToString("yyyyy")Here is the complete code −Example Live Demousing System; using System.Threading; using System.Diagnostics; public class Demo { public static void Main() { DateTime dt = DateTime.Now; // Today's date Console.WriteLine("Today = {0}", DateTime.Today); Console.WriteLine("Displaying current year in dufferent formats:"); Console.WriteLine(dt.ToString("yy")); Console.WriteLine(dt.ToString("yyy")); Console.WriteLine(dt.ToString("yyyy")); Console.WriteLine(dt.ToString("yyyyy")); } }OutputToday = 9/4/2018 12:00:00 AM Displaying current year in dufferent formats: 18 2018 2018 02018
The Ulong type in C# is an alias to the System.UInt64 type. It is an Unsigned integer.Set the Ulong type −ulong val = 7712059531;To get the minimum and maximum value for Ulong type −Console.WriteLine(ulong.MaxValue); Console.WriteLine(ulong.MinValue);Here is the complete code −Example Live Demousing System; using System.Threading; using System.Diagnostics; public class Demo { public static void Main() { ulong val = 7712059531; Console.WriteLine(val); // Max and Min values Console.WriteLine(ulong.MaxValue); Console.WriteLine(ulong.MinValue); // typeof Console.WriteLine(typeof(ulong)); } }Output7712059531 18446744073709551615 0 System.UInt64
We can use the similar syntax of the WHERE...LIKE clause into the PHP function – mysql_query(). This function is used to execute the SQL command and later another PHP function – mysql_fetch_array() can be used to fetch all the selected data if the WHERE...LIKE clause is used along with the SELECT command.But if the WHERE...LIKE clause is being used with the DELETE or UPDATE command, then no further PHP function call is required.To illustrate it we are having the following example −ExampleIn this example, we are writing a PHP script that will return all the records from the table named ‘tutorial_tbl’ ... Read More
ContainsKey is a Dictionary method in C# and check whether a key exists in the Dictionary or not.Declare a Dictionary and add elements −var dict = new Dictionary() { {"TV", 1}, {"Home Theatre", 2}, {"Amazon Alexa", 3}, {"Google Home", 5}, {"Laptop", 5}, {"Bluetooth Speaker", 6} };Now, let’s say you need to check for the existence of a particular element in the Dictionary. For that, use the ContainsKey() method −if (dict.ContainsKey("Laptop") == true) { Console.WriteLine(dict["Laptop"]); }The following is the code −Example Live Demousing System; using System.Collections.Generic; public class Demo { public static void Main() ... Read More
As we know that MySQL supports foreign key for referential integrity but it does not support CHECK constraint. But we can emulate them by using triggers. It can be illustrated with the help of an example given below −ExampleSuppose we have a table named ‘car1’ which can have the fix syntax registration number like two letters, a dash, three digits, a dash, two letters as follows −mysql> Create table car1 (number char(9)); Query OK, 0 rows affected (0.32 sec) mysql> Insert into car1 values('AB-235-YZ'); Query OK, 1 row affected (0.10 sec)The above value is a valid one but what ... Read More
To convert a string to a bool, use the Bool.parse method in C# −Firstly, set a string −string str = "false";Now, convert it to bool −bool.Parse(str);Here is the complete code −Example Live Demousing System; using System.Linq; class Demo { static void Main() { string str = "false"; bool res = bool.Parse(str); Console.WriteLine(res); } }OutputFalse
To convert a string to a long, use the Long.parse method in C# −Firstly, set a string −string str = "6987646475767";Now, convert it to long −long.Parse(str);Here is the complete code −Example Live Demousing System; using System.Linq; class Demo { static void Main() { string str = "6987646475767"; long res = long.Parse(str); Console.WriteLine(res); } }Output6987646475767
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP