Posts

Showing posts from January, 2018

Difference between array, arraylist, List, Hashtable, Dictionary and SortedList in c#

Basic difference is that arrays are of fixed size. Whereas an ArrayList implements the list data structure and can dynamically grow. While arrays would be more performance that a list, a list would be far more flexible since you don't need to know the required size initially. Array - represents an old-school memory array - kind of like a alias for a normal type[] array. Can enumerate. Can't grow automatically. I would assume very fast insertion, retrieve and speed. ArrayList - automatically growing array. Adds more overhead. Can enum., probably slower than a normal array but still pretty fast. These are used a lot in .NET List - one of my favorites - can be used with generics, so you can have a strongly typed array, e.g. List . Other than that, acts very much like ArrayList. Hashtable - plain old hashtable. O(1) to O(n) worst case. Can enumerate the value and keys properties, and do key/val pairs. Dictionary - same as above only strongly typed via generics, such a...

Difference between array, arraylist, List, Hashtable, Dictionary and SortedList in c#

Basic difference is that arrays are of fixed size. Whereas an ArrayList implements the list data structure and can dynamically grow. While arrays would be more performance that a list, a list would be far more flexible since you don't need to know the required size initially. Array - represents an old-school memory array - kind of like a alias for a normal type[] array. Can enumerate. Can't grow automatically. I would assume very fast insertion, retrieve and speed. ArrayList - automatically growing array. Adds more overhead. Can enum., probably slower than a normal array but still pretty fast. These are used a lot in .NET List - one of my favorites - can be used with generics, so you can have a strongly typed array, e.g. List . Other than that, acts very much like ArrayList. Hashtable - plain old hashtable. O(1) to O(n) worst case. Can enumerate the value and keys properties, and do key/val pairs. Dictionary - same as above only strongly typed via generics, such a...

Difference between IEnumerable VS IQueryable in c#

In LINQ to query data from database and collections, we use IEnumerable and IQueryable for data manipulation. IEnumerable is inherited by IQueryable, Hence IQueryable has all the features of IEnumerable and except this, it has its own features. Both have its own importance to query data and data manipulation. Let’s see both the features and take the advantage of both the features to boost your LINQ Query performance. IEnumerable IEnumerable exists in System.Collections Namespace. IEnumerable can move forward only over a collection, it can’t move backward and between the items. IEnumerable is best to query data from in-memory collections like List, Array etc. While query data from database, IEnumerable execute select query on server side, load data in-memory on client side and then filter data. IEnumerable is suitable for LINQ to Object and LINQ to XML queries. IEnumerable supports deferred execution. IEnumerable doesn’t supports custom query. IEnumerable doesn’t support lazy loading. H...

Difference between DataTable.Copy() Vs. DataTable.Clone() in C#

Image
Two major methods of DataTable in C#, One is Copy() and the other one is Clone() . Though these two sound identical but there are huge differences between these two. There are two things to copy or clone of a DataTable . These are structure and data . Copy and Clone are playing with these two. Let us create a DataTable first. DataTable dt = new DataTable(); dt.Columns.Add( " Id" ); dt.Columns.Add( " Name" ); dt.Columns.Add( " Email" ); dt.TableName = " MasterTable" ; // insert into DataTable dt.Rows.Add( " 1" , " Arka" , " arka@gmail.com" ); dt.Rows.Add( " 2" , " Anusua" , " anu@gmail.com" ); dt.Rows.Add( " 3" , " Sayantani" , " sayantani@gmail.com" );     DataTable.Copy() returns a DataTable with the structure and data of the DataTable . // Creating another DataTable to copy DataTable dt_copy = new DataTable(); dt.TableName = " CopyTable...