c# - How to pass multiple arguments to a method?

C# - I have a method which requires 9 arguments (3 are int and 6 are string). What is the best way to deal with this? How should i call the method without specifying so many arguments.

Method looks something like this

public void addProfileData(string profileText, string emailText, string serverText, int repeatText, int timeoutText, string urlText, string elementIDText, string textToBeVerifiedText, int benchmarkTime)
{
    int pid = -1;
    SqlCommand myCommand = new SqlCommand("AddProfileInformation", myConnection);
    myCommand.CommandType = CommandType.StoredProcedure;
    SqlParameter paramprofileText = new SqlParameter("@profileText", SqlDbType.NVarChar);
    paramprofileText.Value = profileText;
    myCommand.Parameters.Add(paramprofileText);

    SqlParameter paramemailText = new SqlParameter("@emailText", SqlDbType.NVarChar);
    paramemailText.Value = emailText;
    myCommand.Parameters.Add(paramemailText);

    myConnection.Open();
    using (SqlDataReader rdr = myCommand.ExecuteReader(CommandBehavior.CloseConnection))
    {
        while (rdr.Read())
        {
            pid = rdr.GetInt32(rdr.GetOrdinal("pid"));
        }
        rdr.Close();
    }
    myConnection.Close();
    if (pid != -1)
    {
        addPingData(serverText, repeatText, timeoutText, pid);
        addPLTData(urlText, elementIDText, textToBeVerifiedText, benchmarkTime, pid);
    }
}
5
задан Jon Skeet 11 April 2011 в 06:14
поделиться