Using the default, you can get the default value of every reference and value type. The expressions set as default are evaluated at compile-time.To get the default for int −default(int);To get the default for long −default(long)Let us see the code to display default values −Example Live Demousing System; public class Demo { public static void Main() { int val1 = default(int); long val2 = default(long); bool val3 = default(bool); // default for int Console.WriteLine(val1); // default for long Console.WriteLine(val2); // default for bol Console.WriteLine(val3); } }Output0 0 False
Use the default operator to get the default value of StringBuilder.StringBuilder str = default(StringBuilder);Above, we have used the default keywords to get the default value.Let us see the complete code −Example Live Demousing System; using System.Text; public class Demo { public static void Main() { StringBuilder str = default(StringBuilder); Console.WriteLine("Default for StringBuilder = "+str); } }OutputDefault for StringBuilder =The following is the output. It shows a blank space i.e. Null.Default for StringBuilder = Null
Use the default operator to get the default value of bool type −bool a = default(bool);Above, we have used the default keyword to get the default value.Let us see the code to display default value of bool −Example Live Demousing System; public class Demo { public static void Main() { bool a = default(bool); // default for bool Console.WriteLine("Default for bool type = "+a); } }OutputThe following is the output. It shows a blank space i.e. False.Default for bool type = False
MySQL views can be created by using a combination of logical operators like AND, OR, and NOT. It can be illustrated with the help of following examples −Examplemysql> Create or Replace View Info AS select ID, Name, Address , Subject FROM Student_info WHERE (Subject = 'Computers' AND ADDRESS = 'Delhi') OR (Subject = 'History' AND Address = 'Amritsar'); Query OK, 0 rows affected (0.11 sec) mysql> Select * from Info; +------+-------+---------+-----------+ | ID | Name | Address | Subject | +------+-------+---------+-----------+ | 133 | Mohan | Delhi | Computers | +------+-------+---------+-----------+ 1 row in set (0.00 sec)
The nameof operator returns a string literal of an element that can be a variable, type or member.For example, the following is our variable −var vehicle = "motorbike";To get the string literal, use nameof −nameof(vehicle);The following is the code to implement nameof keyword −Example Live Demousing System; public class Program { static void Main() { var vehicle = "motorbike"; Console.WriteLine(nameof(vehicle)); var time = DateTime.Now.ToLocalTime(); Console.WriteLine(nameof(time)); var a = false; Console.WriteLine(nameof(a)); } }Outputvehicle time a
Use the Remove() method to remove a range of characters by index.Let’s say you need to remove the last 5 characters from the following string −StringBuilder myStr = new StringBuilder("Framework");For that, set the Remove() method as −str.Remove(3, 4);The following is the complete code −Example Live Demousing System; using System.Text; public class Program { public static void Main() { StringBuilder myStr = new StringBuilder("Framework"); Console.WriteLine("Initial String: " + myStr); // removing four characters Console.Write("New string: "); myStr.Remove(5, 4); Console.WriteLine(myStr); } }OutputInitial String: Framework New string: Frame
Declare a char array and set the size −char[] arr = new char[5];Now set the elements −arr[0] = 'h'; arr[1] = 'a'; arr[2] = 'n'; arr[3] = 'k'; arr[4] = 's';Let us see the complete code now to declare, initialize and display char arrays in C# −Example Live Demousing System; public class Program { public static void Main() { char[] arr = new char[5]; arr[0] = 'h'; arr[1] = 'a'; arr[2] = 'n'; arr[3] = 'k'; arr[4] = 's'; Console.WriteLine("Displaying string elements..."); for (int i = 0; i < arr.Length; i++) { Console.WriteLine(arr[i]); } } }OutputDisplaying string elements... h a n k s
To compare two values, use the CompareTo() method.The following are the return values −0 = both the numbers are equal1 = second number is smaller-1 = first number is smallerHere is the code to implement CompareTo() method in C# −Example Live Demousing System; public class Demo { public static void Main() { int val1 = 100; int val2 = 100; int res = val1.CompareTo(val2); Console.WriteLine(res); } }Output0
The GroupBy() is an extension method that returns a group of elements from the given collection based on some key value.The following is our array −int[] arr = { 2, 30, 45, 60, 70 };Now, we will use GroupBy() to group the elements smaller than 50 −arr.GroupBy(b => chkSmaller(b));The above chkSmaller() finds the elements smaller than 50.Let us see the complete code −Example Live Demousing System; using System.Linq; class Demo { static void Main() { int[] arr = { 2, 30, 45, 60, 70 }; var check = arr.GroupBy(b => chkSmaller(b)); ... Read More
The INFORMATION_SCHEMA database has a VIEWS table that contains view metadata i.e. data about views. To illustrate it we are taking the example of a view named ‘Info’.ExampleThe following query will show the metadata of a view named ‘Info’ −mysql> SELECT * from INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = 'Info' AND TABLE_SCHEMA = 'query'\G *************************** 1. row *************************** TABLE_CATALOG: def TABLE_SCHEMA: query TABLE_NAME: info VIEW_DEFINITION:select`query`.`student_info`.`id`AS`ID`, `query`.`student_info`.`Name` AS `NAME`, `query`.`student_info`.`Subject` AS `SUBJECT`, `query`.` student_info`.`Address` AS `ADDRESS` from `query`.`student_info` CHECK_OPTION: NONE IS_UPDATABLE: YES DEFINER: root@localhost ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP