Which one of the following code samples implements an indexer?
Choice 1
class CSharp {
public Item[int idx] {
get {...}
set {...}
}
}
Choice 2
class CSharp {
public object Item[int idx] {
get {...}
set {...}
}
}
Choice 3
class CSharp {
public object this[int idx] {
get {...}
set {...}
}
}
Choice 4
class CSharp {
public object CSharp[int idx] {
get {...}
set {...}
}
}
Choice 5
class CSharp {
public class Item[int idx] {
get {...}
set {...}
}
}
-->
C# introduces a new concept known as Indexers which are used for treating an object as an array. The indexers are usually known as smart arrays in C# community. Defining a C# indexer is much like defining properties. We can say that an indexer is a member that enables an object to be indexed in the same way as an array.
this [argument list]
{
get
{
// Get codes goes here
}
set
{
// Set codes goes here
}
}
Ans is 3 .
2. what is the differnece between readonly and const variables?
--> Const variable, value specified on design time
3. What is a static constructor in C#?
-->
Things to know about Static Constructor
- It is used to initialize static data members.
- Can't access anything but static members.
- Can't have parameters
- Can't have access modifiers like Public, Private or Protected.
No comments:
Post a Comment