Reusing Code Snippets

Discussion in 'ASP .Net' started by - Steve -, Sep 30, 2004.

  1. - Steve -

    - Steve - Guest

    I'm working on my asp.net site and I'm wondering what the best way to reuse
    little snippets of code is?

    Right now I have a Class in it's own cs file that I call Snippets. Then
    when I want to use something in there (like for example I have
    Snippets.Logout()) I do the following.

    Snippets snips = new Snippets();
    snips.LogOut();

    But what I really want to do is just run Snippets.Logout(), like for all
    functions that come with .Net.
     
    - Steve -, Sep 30, 2004
    #1
    1. Advertising

  2. - Steve -

    Greg Burns Guest

    In VB you would make your Snippets class Shared. In C# it is static.

    Greg

    "- Steve -" <> wrote in message
    news:...
    > I'm working on my asp.net site and I'm wondering what the best way to
    > reuse little snippets of code is?
    >
    > Right now I have a Class in it's own cs file that I call Snippets. Then
    > when I want to use something in there (like for example I have
    > Snippets.Logout()) I do the following.
    >
    > Snippets snips = new Snippets();
    > snips.LogOut();
    >
    > But what I really want to do is just run Snippets.Logout(), like for all
    > functions that come with .Net.
    >
     
    Greg Burns, Sep 30, 2004
    #2
    1. Advertising

  3. - Steve -

    Greg Burns Guest

    What I meant to say was declare all your methods as Shared/static. And make
    your constructor private.

    Public Class Snippets
    Private Sub New()
    End Sub

    Public Shared Function DoSomething() As Object
    'blah blah
    End Function
    End Class

    Greg

    "Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
    news:%...
    > In VB you would make your Snippets class Shared. In C# it is static.
    >
    > Greg
    >
    > "- Steve -" <> wrote in message
    > news:...
    >> I'm working on my asp.net site and I'm wondering what the best way to
    >> reuse little snippets of code is?
    >>
    >> Right now I have a Class in it's own cs file that I call Snippets. Then
    >> when I want to use something in there (like for example I have
    >> Snippets.Logout()) I do the following.
    >>
    >> Snippets snips = new Snippets();
    >> snips.LogOut();
    >>
    >> But what I really want to do is just run Snippets.Logout(), like for all
    >> functions that come with .Net.
    >>

    >
    >
     
    Greg Burns, Oct 1, 2004
    #3
    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. Pat

    Where are my Code Snippets?

    Pat, Apr 20, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    402
    Simon Harris
    Apr 23, 2005
  2. Steve Franks
    Replies:
    2
    Views:
    371
    Juan T. Llibre
    Sep 11, 2005
  3. Edwin Knoppert
    Replies:
    0
    Views:
    378
    Edwin Knoppert
    Nov 30, 2005
  4. Committing Code Snippets

    , Dec 17, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    355
  5. Replies:
    14
    Views:
    749
    Flash Gordon
    Nov 20, 2007
Loading...

Share This Page