Click here to Skip to main content
15,899,679 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I have some doubts>

1) What is the default capacity of a collection(say a hashtable or a list etc)?
2) Suppose i say :

int[] d; ////compile time error
static int[] d;////run time error

why so?

3) Why can we not add a return statement in the "finally" clause after the try and catch statement?

4) What is the exact significance of "this" keyword?


Thanks and regards
Posted

1 solution

1) There isn't one defined - which means that it isn't anything your should rely on as it's an implementation detail and subject to change without notice in future updates. A quick check with Reflector says that List and Dictionary are initialized to empty, but increase their size in different ways.
2) Since when?
3) Because when you have a finally clause in C#, the C# specification states that every statement within the finally clause must execute. Because of this, it is not possible to use a return statement within a finally clause as it could allow statements to be "missed". In addition, what should happen here?
C#
private int MyMethod()
    {
    try
        {
        return SomeFunctionReturningInt();
        }
    finally
        {
        return -1;
        }
    }
SomeFunctionReturningInt would have to be called before the finally block, and then the finally tries to establish the return value? Nasty!
4) this is the current instance of the class at runtime. Most of teh time you don't need it at all, but it allows you to pass the current instance to a method:
C#
int i = GetValue(this);
Or to clarify exactly which value you mean when a local value overrides a class level value:
C#
private int setting;
private void DoSomething(int setting)
    {
    this.setting = setting;
    }
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900