简体   繁体   English

已经定义了一个使用相同参数类型调用的成员 c#

[英]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.

相关问题 C#错误:类型'x'已经定义了一个名为'y'的成员,它具有相同的参数类型 - C# error: Type 'x' already defines a member called 'y' with the same parameter types C#:专用模板方法-错误:类型“…”已经定义了具有相同参数类型的成员“…” - C#: specialized template method - Error: Type '…' already defines a member called '…' with the same parameter types 错误 CS0111:“程序”类型已经定义了一个名为“Main”的成员,具有相同的参数类型 c# - error CS0111: Type 'Program' already defines a member called 'Main with the same parameter types c# 类型&#39;Startup&#39;已经定义了一个名为&#39;Configuration&#39;的成员,它具有相同的参数类型 - Type 'Startup' already defines a member called 'Configuration' with the same parameter types 已经使用相同的参数类型定义了一个名为“InitializeComponent”的成员 - Already defines a member called 'InitializeComponent' with the same parameter types Web Api已经使用相同的参数类型定义了一个名为“ Get”的成员 - Web Api already defines a member called 'Get' with the same parameter types 错误已使用相同的参数类型定义了一个名为“索引”的成员 - Error already defines a member called 'Index' with the same parameter types 错误 - 已经使用相同的参数类型定义了一个名为“InitializeComponent”的成员 - Error - already defines a member called 'InitializeComponent' with the same parameter types “&#39;Form1&#39; 已经定义了一个名为 &#39;.ctor&#39; 的成员,具有相同的参数类型” - "'Form1' already defines a member called '.ctor' with the same parameter types " 错误1类型“ Pay”已经使用相同的参数类型定义了一个名为“ ComputePay”的成员 - Error 1 Type 'Pay' already defines a member called 'ComputePay' with the same parameter types
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM