Found 26504 Articles for Server Side Programming

HybridDictionary Class in C#?

AmitDiwan
Updated on 16-Dec-2019 06:41:19

182 Views

The HybridDictionary class implements IDictionary by using a ListDictionary while the collection is small, and then switching to a Hashtable when the collection gets large.Following are the properties of the HybridDictionary class −Sr.NoProperty & Description1CountGets the number of key/value pairs contained in the HybridDictionary.2IsFixedSizeGets a value indicating whether the HybridDictionary has a fixed size.3IsReadOnlyGets a value indicating whether the HybridDictionary is read-only.4IsSynchronizedGets a value indicating whether the HybridDictionary is synchronized (thread safe).5Item[Object]Gets or sets the value associated with the specified key.6KeysGets an ICollection containing the keys in the HybridDictionary.7SyncRootGets an object that can be used to synchronize access to the ... Read More

How to get Synchronize access to an Array in C#?

AmitDiwan
Updated on 16-Dec-2019 06:35:10

151 Views

To get synchronize access to an array, the code is as follows −Example Live Demousing System; public class Demo {    public static void Main() {       Array intArr = new int[] {5, 10, 15, 20, 25, 30, 35, 40 };       Console.WriteLine("Integer array...");       foreach (int i in intArr)       Console.WriteLine(i);       Console.WriteLine("After applying lock on array...");       lock(intArr.SyncRoot) {          foreach (Object ob in intArr)          Console.WriteLine(ob);       }    } }OutputThis will produce the following output −Integer array... 5 ... Read More

Add an object to the end of Collection in C#

AmitDiwan
Updated on 16-Dec-2019 06:29:59

242 Views

To add an object to the end of Collection, the code is as follows −Exampleusing System; using System.Collections.ObjectModel; public class Demo {    public static void Main() {       Collection col = new Collection();       col.Add(10);       col.Add(20);       col.Add(30);       col.Add(40);       col.Add(50);       col.Add(60);       col.Add(70);       col.Add(80);       Console.WriteLine("Elements in the Collection...");       foreach(int val in col) {          Console.WriteLine(val);       }       Console.WriteLine("Does the collection has the ... Read More

Add a string to the end of the StringCollection in C#

AmitDiwan
Updated on 16-Dec-2019 06:26:11

111 Views

To add a string to the end of the StringCollection, the code is as follows −Exampleusing System; using System.Collections.Specialized; public class Demo {    public static void Main() {       StringCollection strCol = new StringCollection();       strCol.Add("John");       strCol.Add("Tim");       strCol.Add("Gary");       strCol.Add("Katie");       strCol.Add("Andy");       strCol.Add("Amy");       strCol.Add("Scarlett");       strCol.Add("Jacob");       Console.WriteLine("Elements in StringCollection...");       foreach(Object ob in strCol) {          Console.WriteLine(ob);       }       Console.WriteLine("Count of elements = "+strCol.Count); ... Read More

How to get all elements of a List that match the conditions specified by the predicate in C#?

AmitDiwan
Updated on 16-Dec-2019 06:22:50

631 Views

To get all elements of a List that match the conditions specified by the predicate, the code is as follows −Exampleusing System; using System.Collections.Generic; public class Demo {    private static bool demo(int i) {       return ((i % 3) == 0);    }    public static void Main(String[] args) {       List list = new List();       list.Add(9);       list.Add(15);       list.Add(20);       list.Add(40);       list.Add(50);       list.Add(60);       Console.WriteLine("List elements...");       foreach (int i in list) {   ... Read More

How to get hash code for the specified key of a Hashtable in C#?

AmitDiwan
Updated on 16-Dec-2019 06:19:21

263 Views

To get hash code for the specified key of a Hashtable, the code is as follows −Example Live Demousing System; using System.Collections; public class HashCode : Hashtable {    public static void Main(string[] args) {       HashCode hash = new HashCode();       hash.Add("A", "Jacob");       hash.Add("B", "Mark");       hash.Add("C", "Tom");       hash.Add("D", "Nathan");       hash.Add("E", "Tim");       hash.Add("F", "John");       hash.Add("G", "Gary");       Console.WriteLine("Key and Value pairs...");       foreach(DictionaryEntry entry in hash) {          Console.WriteLine("{0} and {1} ", ... Read More

How to get Synchronize access to the ListDictionary in C#?

AmitDiwan
Updated on 16-Dec-2019 06:15:05

169 Views

To get synchronize access to the ListDictionary, the code is as follows −Example Live Demousing System; using System.Collections; using System.Collections.Specialized; public class Demo {    public static void Main() {       ListDictionary dict = new ListDictionary();       dict.Add("1", "SUV");       dict.Add("2", "Sedan");       dict.Add("3", "Utility Vehicle");       dict.Add("4", "Compact Car");       dict.Add("5", "SUV");       dict.Add("6", "Sedan");       dict.Add("7", "Utility Vehicle");       dict.Add("8", "Compact Car");       dict.Add("9", "Crossover");       dict.Add("10", "Electric Car");       Console.WriteLine("ListDictionary elements...");       ... Read More

Fetch the maximum value from a MySQL column?

AmitDiwan
Updated on 11-Dec-2019 11:49:37

211 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> Value int    -> ); Query OK, 0 rows affected (0.63 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(78); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(89); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values(98); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(58); Query OK, 1 row affected (0.25 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output ... Read More

ORDER BY rand() and keep them grouped in MySQL?

AmitDiwan
Updated on 11-Dec-2019 11:48:38

270 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> StudentMarks int    -> ); Query OK, 0 rows affected (0.58 sec)Insert some records in the table using insert command. We have also inserted duplicate records −mysql> insert into DemoTable(StudentMarks) values(98); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable(StudentMarks) values(98); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable(StudentMarks) values(78); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable(StudentMarks) values(78); Query OK, 1 row affected (0.29 sec) mysql> insert ... Read More

Insert data from one table to another in MySQL?

AmitDiwan
Updated on 11-Dec-2019 11:44:49

991 Views

To insert data from one table to another, use the INSERT INTO SELECT statement. Let us first create a table −mysql> create table DemoTable1    -> (    -> Id int,    -> FirstName varchar(20)    -> ); Query OK, 0 rows affected (0.49 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1 values(101, 'Adam'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1 values(102, 'John'); Query OK, 1 row affected (0.11 sec)Display all records from the table using select statement −mysql> select *from DemoTable1;This will produce the following output −+------+-----------+ | Id   ... Read More

Advertisements