Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

already defines a member called with the same parameter types c#

Tags:

c#

Just as title says i have this error already defines a member called with the same parameter types c#

I have looked into multiple same questions but they all tells why does it happens and how to deal with it (change name of method to some other) BUT i do not want to change method name to something other because it is same method but with different parameter so i just want to bypass it.

Here are 2 methods i have:

public static List<int> Lista(int vrDok)
{
    List<int> list = new List<int>();
    using (FbConnection con = new FbConnection(M.Baza.connectionKomercijalno2018))
    {
        con.Open();
        using (FbCommand cmd = new FbCommand("SELECT BRDOK FROM DOKUMENT WHERE VRDOK = @VrDok ORDER BY DATUM ASC", con))
        {
            cmd.Parameters.AddWithValue("@VrDok", vrDok);

            FbDataReader dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                list.Add(Convert.ToInt32(dr[0]));
            }
        }
    }
    return list;
}
public static List<int> Lista(int magacinId)
{
    List<int> list = new List<int>();
    using (FbConnection con = new FbConnection(M.Baza.connectionKomercijalno2018))
    {
        con.Open();
        using (FbCommand cmd = new FbCommand("SELECT BRDOK FROM DOKUMENT WHERE MAGACINID = @MID ORDER BY DATUM ASC", con))
        {
            cmd.Parameters.AddWithValue("@MID", magacinId);

            FbDataReader dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                list.Add(Convert.ToInt32(dr[0]));
            }
        }
    }
    return list;
}

So as you can see they are totally identical but with different parameter and it drops me error.

How can i bypass it?

like image 343
Aleksa Ristic Avatar asked Sep 03 '25 06:09

Aleksa Ristic


2 Answers

It gives error because the method signature is the same

  • Lista(int)
  • Lista(int)

The parameters name doesn't matter only the method name and the parameters type are considered.

You can resolve by changing the name of one method (ex. ListaByVrDok, ListaByMagician)

like image 129
Davide Pizzolato Avatar answered Sep 04 '25 18:09

Davide Pizzolato


Any of Davide suggestions will work. Another options is to do just have one method that takes the ID and the Parameter Name like so:

public static List<int> Lista(int id,string paramName)
{
    List<int> list = new List<int>();
    using (FbConnection con = new FbConnection(M.Baza.connectionKomercijalno2018))
    {
        con.Open();
        using (FbCommand cmd = new FbCommand("SELECT BRDOK FROM DOKUMENT WHERE MAGACINID = @MID ORDER BY DATUM ASC", con))
        {
            cmd.Parameters.AddWithValue(paramName, id);

            FbDataReader dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                list.Add(Convert.ToInt32(dr[0]));
            }
        }
    }
    return list;
}

Since everything in both methods are the same and just which parameter name changes.

like image 20
Hagashen Naidu Avatar answered Sep 04 '25 18:09

Hagashen Naidu