1.
Array
is strongly typed and can store only same type of data whileArrayList
can store any type of data.2.
Array
stores fixed number of elements whileArrayList
can store any number of elements as it grows dynamically.3. In
Array
no need to cast elements while retrieving whereas inArrayList
items need to be cast to appropriate data type while retrieving.
1.
String
is immutable i.e. if we create a string object then we can't modify it & it always creates new object of string type in memory whileStringBuilder
is mutable i.e. if we create StringBuilder object then we can perform any operation like insert, replace or append without creating new instance every time.2.
String
belongs to System class whileStringBuilder
belongs to System.Text class.
1.
ArrayList
stores only the value at a particular index whileHashTable
stores data as Key-Value pair.2. To access value from
ArrayList
, index number should be passed while to access value fromHashTable
key should be passed.
Both loops are used when a unit of code needs to execute repeatedly.
For loop
is used when you know how many times you need to iterate through the code whereaswhile loop
is used when you need to repeat something until a given statement is true.
```C# int i =13; object myObject = i; //Boxing-implicit i = (int)myObject; //Unboxing-explicit ```Boxing is converting a value type to an object type.
Unboxing is extracting the value type from the object type.
1.
Constants
are evaluated compile-time whileRead-Only variables
are evaluated at runtime.2.
Constants
only support value-type variables whileRead-Only variables
can hold reference type variables.3.
Constants
should be used when the value won't change during runtime whileRead-Only variables
are used mostly when their actual value is unknown before the runtime.
1.
==
is the comparison operator whileEquals()
compares the contents of a String.2.
==
compares the reference identity as well as the contents whileEquals()
compares only the contents.
1.
Finalize
is used to free unmanaged resources like files, database connections, etc held by an object before that object is destroyed. Internally, it is called by Garbage Collector & can't be called by user code whileDispose
is used to free unmanaged resources at any time. Explicitally, it is called by user code.2.
Finalize
belongs to the Object class whileDispose
belongs to IDisposable interface and the class which is implementing Dispose method must implement this interface.
The default access for a class is Internal & the default access for members is Private.
```C# try { Console.WriteLine("Sample Data"); } catch (NullPointerException ex) { Console.WriteLine("NullPointerException"); } catch (Exception e) { Console.WriteLine("Exception"); } ```No. We can use multiple catch blocks with every try but when an Exception is thrown by the debugger, it tries matching the exception type with their signature and catch the exception by the particular catch block, so we can use multiple catch blocks but only one catch can be executed at once.
'this' keyword can't be used in static methods because it returns a reference to the current instance of the class containing it. Static methods can't be instantiated, so they are called by the name of a class and not by instance. Therefore, we can’t use 'this' keyword in the body of static methods.
By definition, 'this' keyword is a special type of reference variable that is implicitly defined within each constructor and non-static method as a first parameter of the type class in which it is defined.
This book is released under a Creative Commons Attribution-Noncommercial- No Derivative Works 3.0 United States License.
What this means is that it is free to read and use, but the license does not permit commercial use of the material (i.e you can freely print out the questions for your own use, but you can't sell it). I'm trying to help so I would greatly appreciate it if you would respect these terms.
Copyright Aditya Kumar, 2017.