Accessing public methods without creating object...

Posted on 2006-04-25
Last Modified: 2010-04-16

In VB.NET I have a Class file (called Common) with some code:

Public Shared Sub BindCombos()
End Sub

I could then populate a combobox by doing:

Common.BindCombos(param1, 2 etc)

And this was enough.

I tried doing this in C# and it will not let me do this.

In C# I have to create an object from the class:

Common myCbo = new CommonUtils();
myCbo.BindCbos(param1, 2 etc);

Compiles and runs but is not doing the job i.e. not populating my control.

How can I just create a separate class/code file that has generic functions I can call??


Question by:saleek
    LVL 48

    Accepted Solution

    Public Shared Sub BindCombos()

    in C#:

    public static void BindCombos()

    LVL 11

    Author Comment

    Lovely jubbly!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Suggested Solutions

    Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
    Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now