problem of datareader

  • Thread starter Thread starter prabhat tiwari
  • Start date Start date
P

prabhat tiwari

as sqldatareader is a class so why we can not create object of that class directly using new keyword.
 
prabhat said:
as sqldatareader is a class so why we can not create object of that class directly using new keyword.

SqlDataReader class hasn't got constructor, so you cannot instantiate
that class.

We user SqlDataReader only when we use commandobject.ExecuteReader()
method.
 
Hi,


There are classes that are not intended to be created by the user, only
methods from the same library can internally create them and return an
instance. These classes are refered to as noncreatable classes.

There are numerous examples of these kind of classes in the framework.

I was trying to look for a good definition but was unable to find one, so
take the above explanation as a starting point and maybe somebody else will
post a more detailed explanation
 
first of all thanks for reply i know that sqlcommand's executereader method give the instance of sqldatareader but why we can not make it directly and i know that you can not make a instance of the class
1.it should be abstract
2.it have private constrcutor.
what can be the possibilty try to find out n share with us
 
i just want to know how can we create such type of class it will some intersting point about class which we do not know
 
Hi

i just want to know how can we create such type of class it will some
intersting point about class which we do not know

The secret is in how you declare the constructor of the type:

1- Declare it private, in this case you will have to provide a static method
that return an instance:

class C{
static public C GetA_C() { return new C();}
private C(){}
}

2- Declare it internal (as in the case of the Reader), in this way another
class define din the same assembly can call it

class C{

internal C(){}
}

class D{
public C GetA_C(){ return new C();}
}
 

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

Back
Top