C# questions about basic constructs

P

puzzlecracker

.... I am coming off c++, so here is the list of question, I'd like to
get clarifications.

1. What's and the point of static constructor?

2. Why C# differs as to base class visibility in regard to Derived
class. In other words, Base class should be at least visible/
accessible as derived.

3. Can we member hiding by re-implementing the method in the derived
class with the same name but different signature and thus hiding the
base member. Here is the illustration:

public class A
{
public foo() {}

}

public class B
{
public foo(int i){}
}


4. Can we pass any type to indexer or only ints?

5.Can a member of a base lass be sealed, and not the whole class, thus
preventing a derived classes overriding it?
 
M

Marc Gravell

1: to initialize static fields / run any other logic that applies to
the type rather than any single instance

3: that doesn't hide the original; it adds an overload. You can hide
the original by re-declaring with the same signature (and ideally, the
"new" modifier), but the original is still available by casting to the
base type.

4: any type

5: yes

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top