Ebeworld’s Weblog

Trying to create

How to prevent a class from initiated?

C#.

1. Declaring class abstract.

2. Declaring constructor private

Also someone said me “3. Declaring static constructor. In this case constructor is guarenteed to use static methods only, not instance variables, so can’t access the instance vairables. In Java this one doesnt work, since java uses static block not static constructor.” but when i tested, it constructor was creating non static instances. Probably compiler keeps static and non static constructors differently.

November 22, 2008 Posted by ebeworld | Uncategorized | | No Comments Yet

C# and Java static constructors

Where should be initialize the static field? If we do it non static initializer, each time when object created the static field will be initialized and that not efficient and may undo what we have done in up to that moment. The solution is to use static constructor. in Java, it is used when class is loaded and written as[it is called static block] 

static{

//..something

}

but in C#, it is accomplished by real static constructor

static MyClass{

//.. do something

}

November 22, 2008 Posted by ebeworld | Interview Questions | | No Comments Yet

Nullabililty in C#

In C# using nullable values like int? would simplify database programming. Unfortunately, java doenst have nullables present until now. Some asked me to use wrapper classes like Integer, but it has 

a. Performance penalty 

b. Integer(1)!=Integer(1)

Also one nice thing is ?? operator which means “if null”.

int? a=null;

int j=a ?? 1;//j=1

November 22, 2008 Posted by ebeworld | Uncategorized | | No Comments Yet