Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question about overloading methods

Status
Not open for further replies.

andegre

MIS
Oct 20, 2005
275
US
I realize this is a very basic question, but is it possible to do this:

Code:
public void PersistData(DataSet ds)
{
    try
    {
        sqlCommand.ExecuteNonQuery()
    }
    catch (Exception ex)
    {
        throw ex
    }
)

public bool PersistData(DataSet ds)
{
    try
    {
        sqlCommand.ExecuteNonQuery()
    }
    catch (Exception ex)
    {
        return false
    }
    return true
}

The question is, can I overload a method with the same parameters for both, but have 1 be a "void" and the other return a boolean value? I know MessageBox.Show() does something like this but I can't remember how...

TIA
 
you can overload the parameters, but not the result.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
as an aside. a common convention is to named the methods according to what they do. example
Code:
public void PersistData(DataSet ds)
{
    sqlCommand.ExecuteNonQuery();
)

public bool [COLOR=blue]Try[/color]PersistData(DataSet ds)
{
    try
    {
        sqlCommand.ExecuteNonQuery();
    }
    catch (Exception ex)
    {
        Log.Exception(ex);
        return false;
    }
    return true;
}

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
How does the MessageBox.Show() method work then? I know you can just call that and show your message, or you can have it return a DialogResult variable...or is that based on the MessageBoxButtons that you define in the MessageBox.Show() parameter list?
 
The signature of MessageBox.Show is
Code:
public static DialogResult Show([overloads])
{
   ...
}

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
MessageBox.Show() always returns a DialogResult? We may not always catch it though . . .

Age is a consequence of experience
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top