is it possible to do the following in C#?
-
Actually i have a class shown below. class demo { DbConnection mConnection; string Connectionstring; }; then i create an object of demo like below demo d=new demo(); Now i want the following oledbcommand comm=new oledbcommand(); comm.connection= d; // what i want here is d should return mConnection and // nothing else. is there any way to do so. Pls help.
-
Actually i have a class shown below. class demo { DbConnection mConnection; string Connectionstring; }; then i create an object of demo like below demo d=new demo(); Now i want the following oledbcommand comm=new oledbcommand(); comm.connection= d; // what i want here is d should return mConnection and // nothing else. is there any way to do so. Pls help.
What you want is against the basic principles of object oriented design and language. No you can't. I suggets you read a C# course book and focus on sections regarding properties. You vvcan attach mConnection to a public property, say you name it Connection. then you can say: comm.connection=d.Connection. You also can make teh member mConnection publc and then you refer to it as: d.mConnection
Rudolf Heijink
-
Actually i have a class shown below. class demo { DbConnection mConnection; string Connectionstring; }; then i create an object of demo like below demo d=new demo(); Now i want the following oledbcommand comm=new oledbcommand(); comm.connection= d; // what i want here is d should return mConnection and // nothing else. is there any way to do so. Pls help.
-
What you want is against the basic principles of object oriented design and language. No you can't. I suggets you read a C# course book and focus on sections regarding properties. You vvcan attach mConnection to a public property, say you name it Connection. then you can say: comm.connection=d.Connection. You also can make teh member mConnection publc and then you refer to it as: d.mConnection
Rudolf Heijink
You *can* do it, via conversion operators. I'd concur that it's not a great idea, but it can be done.
Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
-
Actually i have a class shown below. class demo { DbConnection mConnection; string Connectionstring; }; then i create an object of demo like below demo d=new demo(); Now i want the following oledbcommand comm=new oledbcommand(); comm.connection= d; // what i want here is d should return mConnection and // nothing else. is there any way to do so. Pls help.
You can create a class by inheriting the Connection class.
Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you. :)