can we make a long statement become short by pre-declare it ?

Discussion in 'ASP .Net' started by Tee, Jun 7, 2004.

  1. Tee

    Tee Guest

    Hi,

    my question is as the topic, can we make a long statement become short by
    pre-declare it.
    sorry if you can't understand what I asked, as I am not too sure how to ask
    it, but below is the example of what I want.

    I want just type "Connection", and it will same as "Oledb.OledbConnection",
    so I just need to type Connection.Open instead of
    Oledb.OledbConnection.Open.

    it's not hard to type Oledb.OledbConnection as it is not long, but this is
    just an example of what I want.

    so can anyone tell me how to do it ?


    Thanks.
    Tee, Jun 7, 2004
    #1
    1. Advertising

  2. Tee

    mikeb Guest

    Tee wrote:

    > Hi,
    >
    > my question is as the topic, can we make a long statement become short by
    > pre-declare it.
    > sorry if you can't understand what I asked, as I am not too sure how to ask
    > it, but below is the example of what I want.
    >
    > I want just type "Connection", and it will same as "Oledb.OledbConnection",
    > so I just need to type Connection.Open instead of
    > Oledb.OledbConnection.Open.
    >


    Since OleDbConnection is a class and the Open method is not static, your
    example above would not work. However, in the interest of doing what
    you mean instead of what you say, you could do the following:

    using System.Data.OleDb;

    // ...

    OleDbConnection conn = new OleDbConnection( "my connection string");

    conn.Open();


    Or, to alias the classname itself (which is what I think you were
    getting at):

    using OleConn = System.Data.OleDb.OleDbConnection;

    // ...

    OleConn conn = new OleConn( "my connection string");

    conn.Open();

    Personally, I'd avoid aliasing the classname unless it's required to
    avoid a conflict. If you use OleDbConnection, everyone familiar with
    the ADO.NET namespace immediately knows they're dealing with that class.
    if you alias the classname, then someone reading your code needs to
    know or learn that they're really dealing with OleDbConnection and not
    some custom class.

    Not a big deal, but then using the original classname is generally not
    really a burden in the first place.

    --
    mikeb
    mikeb, Jun 7, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. George Marsaglia

    Assigning unsigned long to unsigned long long

    George Marsaglia, Jul 8, 2003, in forum: C Programming
    Replies:
    1
    Views:
    659
    Eric Sosman
    Jul 8, 2003
  2. Daniel Rudy

    unsigned long long int to long double

    Daniel Rudy, Sep 19, 2005, in forum: C Programming
    Replies:
    5
    Views:
    1,179
    Peter Shaggy Haywood
    Sep 20, 2005
  3. David Geering

    longs, long longs, short short long ints . . . huh?!

    David Geering, Jan 8, 2007, in forum: C Programming
    Replies:
    15
    Views:
    546
    Keith Thompson
    Jan 11, 2007
  4. Juha Nieminen
    Replies:
    3
    Views:
    1,133
    Juha Nieminen
    Feb 22, 2008
  5. TS
    Replies:
    4
    Views:
    109
Loading...

Share This Page