NOTE: This is objective type question, Please click question title for correct answer. |
NOTE: This is objective type question, Please click question title for correct answer. |
If no class is inhertited, by default a class inherit System.Object. |
NOTE: This is objective type question, Please click question title for correct answer. |
This is the new feature in C# 3.0. This enable us to declare a variable whose type is implicitly inferred from the expression used to initialize the variable.
eg.
var age = 10;
Because the initialization value (10) of the variable age is integer type of age will be treated as integer type of variable. There are few limitation of the var type of variables.
They are:
#. They can't be initialized as null.
#. They need to be declared and initialized in the same statement.
#. They can't be used as a member of the class. |
This is a new feature in C# 3.0. This enable use to create a type/class on-the-fly at compile time.
For example
var emp = new { Name = "Sheo", Gender = "Male", Active = true };
In this case a new type will be created on the fly that will have Name, Gender, and Active as public property and its backing field like _Name, _Gender, _Active.
This is especially useful when we want to receive data from other object or iterate through a collection and set values and do not want to create a class just to hold the data. Note that anonymous types are just a placeholder, we can't customize its behavior or add methods inside it. |
This is a new feature in C# 3.0. This method allows us to add a new static method to the existing classes.
For example, if we want to validate an Email address using the static method of the string class (built-in) class, we can add an extension method like this.
public static bool IsValidEmail(this string input)
{
Regex regEx = new Regex(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");
return regEx.IsMatch(input);
}
Notice the parameter passed to above method. Here "this" indicates the string class. Now, we can use above extension method like this.
string myEmail = "me@me.com";
bool IsValidEmailAddress = myEmail.IsValidEmail();
In this case as the format of the email id in myEmail variable is correct so IsValidEmailAddress will be true. |
|
Constructor:
-----------------
1. The Constructor is the first method that is run when an instance of a type is created. In visual basic a constructor is always Sub new ().
2. Constructor are use to initialize class and structure data before use. Constructor never returns a value and can be overridden to provide custom initialization functionality.
3. The constructor provides a way to set default values for data or perform other necessary functions before the object available for use.
Destructor:
---------------
Destructors are called just before an object is destroyed and can be used to run clean-up code. You can’t control when a destructor is called. |
Both CopyTo() and Clone() make shallow copy (data is copied) and used for Single Dimension arrays.
Clone() method makes a clone of the original array. It returns an exact length array.
CopyTo() copies the elements from the original array to the destination array starting at the specified destination array index. Note that, this adds elements to an already existing array.
In VB.NET, variables has to be declared earlier, before using Clone or CopyTo methods to store the values. The difference arise on mentioning the size of the array.
While declaring the varaiable that is used for CopyTo method, it should have the size equal to or more than that of the original array.
While declaring the variable that is used for Clone method we need not mention the array size. Eventhough the array size is small, it won't show any error, rather the array size gets altered automatically on cloning. The cloned array size get created equal to the size of the source array.
If value type is used for CopyTo/Clone any change in the values made on them will not get reflected on the original whereas on reference type the change gets reflected.
Below is the code which would throw some light on your understanding. |
Static:
1)A Static memberdata or a memberfunction can be called without the help of an object.
2)Static members can be called with the help of Classname.
Syntax: classname.staticmember
3)'this ' keyword cannot be used inside a static memberfunction
4)Nonstatic members cannot be used inside a static memberfunction |
StringBuilder is more efficient in cases where there is a large amount of string manipulation. Strings are immutable, so each time a string is changed, a new instance in memory is created. |
1. When the class itself is inherited from an abstract class, but not all base abstract methods have been overridden.
2. When at least one of the methods in the class is abstract. |
A delegate object encapsulates a reference to a method. |
A delegate that has multiple handlers assigned to it. Each assigned handler (method) is called. |
In debug compilation, assert takes in a Boolean condition as a parameter, and shows the error dialog if the condition is false. The program proceeds without any interruption if the condition is true. |