[英]already defines a member called with the same parameter types c#
Just as title says i have this error already defines a member called with the same parameter types c#
正如标题所说,我有这个错误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?我怎样才能绕过它?
It gives error because the method signature is the same 它给出错误,因为方法签名是相同的
- Lista(int) - Lista(int)
- Lista(int) - Lista(int)
The parameters name doesn't matter. 参数名称无关紧要。
You can resolve in different ways: 您可以通过不同方式解决:
- Change the name of one method (ex. ListaByVrDok, ListaByMagician) <= recommended - 更改一个方法的名称(例如ListaByVrDok,ListaByMagician)<= 推荐
- Move one method in another class - 在另一个类中移动一个方法
- Add a parameter to one method - 向一个方法添加参数
- Change int in double in one method - 在一个方法中将double更改为int
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: 另一个选择是只有一个方法来获取ID和参数名称,如下所示:
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. 因为两种方法中的所有内容都相同,只是哪个参数名称更改。
The name I chose for my migration has already been used.我为迁移选择的名称已被使用。
add-migration "added-list-to-model-a"
All I needed to do was to change the name of my migration.我所需要做的就是更改迁移的名称。
add-migration "re-added-list-to-model-a"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.