C#---"CS0535: do not implement interface members" detailed explanation

Recently, the editor is restructuring the computer room. As the saying goes, everything is difficult at the beginning, and the problems are endless, so if you encounter problems, just write it down. The problem that the editor brings today is: (do not implement interface members)

concept:

There are many virtual methods defined in the interface. If you need to inherit this interface when you write a class, you must implement all the virtual methods of this interface in your own class. The following is a detailed display for everyone:

Problem Description:

"LoginDAL"不实现接口成员"LoginIDAL.SelectUser(LoginEntity.UserInfo)"

Code display: Below is the code of my D layer and interface layer

//类实现接口方法
public class LoginDAL : IDAL.LoginIDAL
{
    public DataTable SelectUser(Entity.LoginEntity.UserInfo user)
    {
        //实例化数据操作类,进行数据查询,并获取返回值
        SQLHelper sqlHelper = new SQLHelper();
        SqlParameter[] sqlparms = { new SqlParameter("@UserName", user.UserName), new         SqlParameter("@Password", user.UserPassword) };
        string sql = @"SELECT * FROM [User_Info] WHERE UserName=@UserName AND UserPassword =@ UserPassword
        DataTable table = sqlHelper.ExecuteQuery(sql, sqlparms, CommandType.Text);
        string level = "";
        return table;    
    }
}
//接口层
 public interface LoginIDAL
{
     //写一个判断用户名是否存在user表中的接口
      DataTable SelectUser(Entity.LoginEntity.UserInfo user);
}

solution

First of all, see if the method of this interface implemented by your class is consistent with the method defined by your interface layer. No letter can be wrong. The only difference is that modifiers such as public are used when implementing this interface! Missing modifiers will also report errors!

Secondly, if the code is correct, click the right mouse button on the sentence where the error is reported, and choose to implement the interface. The operation is shown in the following figure:

1. Right-click [Quick Operation and Refactoring...]

2. Then click [Implement Interface]!

Welcome Zhujun to leave a comment!

Guess you like

Origin blog.csdn.net/TGB_Tom/article/details/109696000