To format a string, first set the value −int value = 55;Now to format the integer, use ToString and let’s say we need to set it for three places −value.ToString("000");The following is the complete code −Example Live Demousing System; public class Program { public static void Main() { int value = 55; string res = value.ToString("000"); Console.WriteLine(res); } }Output055
Firstly, set the array −int[] p = new int[] {55, 66, 88, 99, 111, 122, 133};Now, let us say you need to set an element at position 1 −p[2] = 77;Let us see the comple code −Example Live Demousing System; namespace Program { public class Demo { public static void Main(string[] args) { int[] p = new int[] {55, 66, 88, 99, 111, 122, 133}; int j; Console.WriteLine("Initial Array......"); for (j = 0; j < p.Length; j++ ) { ... Read More
Firstly, set a list collection −List < string > myList = new List < string > (); myList.Add("RedHat"); myList.Add("Ubuntu");Now, use ToArray() to convert the list to an array −string[] str = myList.ToArray();The following is the complete code −Example Live Demousing System; using System.Collections.Generic; public class Program { public static void Main() { List < string > myList = new List < string > (); myList.Add("RedHat"); myList.Add("Ubuntu"); Console.WriteLine("List..."); foreach(string value in myList) { Console.WriteLine(value); } ... Read More
Actually, MySQL SIGNAL statement is an error handling mechanism for handling unexpected occurrences and a graceful exit from the application if need to be. Basically, it provides error information to the handler. Its basic syntax would be as follows −SIGNAL SQLSTATE | condition_value [SET signal_information_item = value_1, [, signal_information_item] = value_2, etc;]Here, the SIGNAL keyword is an SQLSTATE value or a condition name declared by a DECLARE CONDITION statement. The SIGNAL statement must always specify an SQLSTATE value or a named condition that defined with an SQLSTATE value. The SQLSTATE value for a The SIGNAL statement consists of a five-character ... Read More
Firstly, set the Hex String −string str = "7D";Now, use the Convert.ToSByte() method to convert the Hex string to Hex number −Console.WriteLine(Convert.ToSByte(str, 16));Let us see the complete code −Example Live Demousing System; namespace Demo { public class Program { public static void Main(string[] args) { string str = "7D"; Console.WriteLine(Convert.ToSByte(str, 16)); } } }Output125Another way of converting Hex String to Hex Number −Example Live Demousing System; namespace Demo { public class Program { public static void Main(string[] args) { string str = "7D"; Console.WriteLine(Convert.ToInt32(str, 16)); } } }Output125
Heterogram for a string means the string isn’t having duplicate letters. For example −Mobile Cry LaptopLoop through each word of the string until the length of the string −for (int i = 0; i < len; i++) { if (val[str[i] - 'a'] == 0) val[str[i] - 'a'] = 1; else return false; }Above, len is the length of the string.Let us see the complete code −Example Live Demousing System; public class GFG { static bool checkHeterogram(string str, int len) { int []val = new int[26]; for (int i ... Read More
Under anagram, another string would have the same characters present in the first string, but the order of characters can be different.Here, we are checking the following two strings −string str1 = "silent"; string str2 = "listen";Convert both the strings into character array −char[] ch1 = str1.ToLower().ToCharArray(); char[] ch2 = str2.ToLower().ToCharArray();Now, sort them −Array.Sort(ch1); Array.Sort(ch2);After sorting, convert them to strings −string val1 = new string(ch1); string val2 = new string(ch2);Compare both the strings for equality. If both are equal, that would mean they are anagrams.The following is the code −Example Live Demousing System; public class Demo { public static ... 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 ‘car’ which can have the fix syntax registration number like two letters, a dash, three digits, a dash, two letters as follows −mysql> Create table car (number char(9)); Query OK, 0 rows affected (0.32 sec) mysql> Insert into car values('AB-235-YZ'); Query OK, 1 row affected (0.10 sec)The above value is a valid one but what ... Read More
Firstly, set both the dictionaries −Dictionary < string, int > dict1 = new Dictionary < string, int > (); dict1.Add("water", 1); dict1.Add("food", 2); Dictionary < string, int > dict2 = new Dictionary < string, int > (); dict2.Add("clothing", 3); dict2.Add("shelter", 4);Now, create HashSet and use UnionsWith() method to find the union between the above two Dictionaries −HashSet < string > hSet = new HashSet < string > (dict1.Keys); hSet.UnionWith(dict2.Keys);The following is the complete code −Example Live Demousing System; using System.Collections.Generic; public class Program { public static void Main() { Dictionary < string, int > dict1 = ... Read More
Firstly, create lists −//three lists var list1 = new List{3, 4, 5}; var list2 = new List{1, 2, 3, 4, 5}; var list3 = new List{5, 6, 7, 8};Use the union method to get the union of list1 and list2 −var res1 = list1.Union(list2); var res2 = res1.Union(list3);The following is the complete code −Example Live Demousing System.Collections.Generic; using System.Linq; using System; public class Demo { public static void Main() { //three lists var list1 = new List{3, 4, 5}; var list2 = new List{1, 2, 3, 4, 5}; var list3 = new List{5, 6, 7, 8}; // finding union var res1 = list1.Union(list2); var res2 = res1.Union(list3); foreach(int i in res2) { Console.WriteLine(i); } } }Output3 4 5 1 2 6 7 8
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP