Question on classes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Keon

    #1

    Question on classes

    I am trying to write a class, but I got stuck.

    When writing a class, how can you call a recursive function that is also in
    the class
    file, but without having to create a new instance of the class before you
    call it.


    // This is my class file

    using System.Data;
    using System.Windows. Forms;

    namespace Misc_Utils
    {
    class InitializeMyDB
    {
    public void PrepareConnecti ons(........)
    {

    // prepare the variables here

    foreach (......)
    {
    StoreDB(....);
    }
    }
    }

    class StoreIntoToDB
    {
    public void StoreDB(....)
    {

    // do my processing here

    foreach (......)
    {
    StoreDB(....);
    }
    }
    }
    }

    Am I stuck with just having to create a new instance of the
    StoreInfoToDB.S toreDB()
    everytime I need to make a call to that function?
    Or is there a way to encapsulate the two functions and make it one class?


    TIA


  • Ian Semmel

    #2
    Re: Question on classes

    I'm not certain as to what you are attempting, but it could be that you
    have a misunderstandin g as to how to use classes.

    I think that what you want is something like

    public class DB
    {
    // define variables etc

    public bool Initialize ()
    {
    // init stuff - setup connection vars etc

    return true;
    }

    public bool Store ()
    {
    // Store stuff - using your connection vars
    return true;
    }
    }

    Then somewhere, for each DB

    DB db = new DB ();

    db.Initialize ();
    db.Store ();


    "Keon" <keon@helloworl d.comwrote in message
    news:ODJ9iR6VIH A.1208@TK2MSFTN GP03.phx.gbl:
    I am trying to write a class, but I got stuck.
    >
    When writing a class, how can you call a recursive function that is also
    in
    the class
    file, but without having to create a new instance of the class before
    you
    call it.
    >
    >
    // This is my class file
    >
    using System.Data;
    using System.Windows. Forms;
    >
    namespace Misc_Utils
    {
    class InitializeMyDB
    {
    public void PrepareConnecti ons(........)
    {
    >
    // prepare the variables here
    >
    foreach (......)
    {
    StoreDB(....);
    }
    }
    }
    >
    class StoreIntoToDB
    {
    public void StoreDB(....)
    {
    >
    // do my processing here
    >
    foreach (......)
    {
    StoreDB(....);
    }
    }
    }
    }
    >
    Am I stuck with just having to create a new instance of the
    StoreInfoToDB.S toreDB()
    everytime I need to make a call to that function?
    Or is there a way to encapsulate the two functions and make it one
    class?
    >
    >
    TIA

    Comment

    Working...