Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. is it possible to do the following in C#?

is it possible to do the following in C#?

Scheduled Pinned Locked Moved C#
csharphelpquestion
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nicolus
    wrote on last edited by
    #1

    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.

    R C M 3 Replies Last reply
    0
    • N nicolus

      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.

      R Offline
      R Offline
      Rudolf Jan
      wrote on last edited by
      #2

      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

      C 1 Reply Last reply
      0
      • N nicolus

        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.

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        Yes, you can define an explict conversion between one class and another. Try this[^]

        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 )

        N 1 Reply Last reply
        0
        • R Rudolf Jan

          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

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          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 )

          1 Reply Last reply
          0
          • C Christian Graus

            Yes, you can define an explict conversion between one class and another. Try this[^]

            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 )

            N Offline
            N Offline
            nicolus
            wrote on last edited by
            #5

            Thanks, i will try it.

            1 Reply Last reply
            0
            • N nicolus

              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.

              M Offline
              M Offline
              Michael Sync
              wrote on last edited by
              #6

              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. :)

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups