T
T
TheTalion2016-10-25 22:24:29
C++ / C#
TheTalion, 2016-10-25 22:24:29

Error: "There is no argument matching the required formal parameter", what is the reason?

The first file contains the following code:

public class PlayerCons
{

  protected Guid m_connectionId;
  protected string m_playerName;

  public Guid ConnectionId { get { return m_connectionId; } }
  public string PlayerName { get { return m_playerName; } }

    public PlayerCons(string _playerName, Guid _connectionId)
  {
    m_playerName = _playerName;
    m_connectionId = _connectionId;
  }
}

In another, like this:
public static void Msg_ws(string message, SomeInterface connection,List<PlayerCons> Connects)
    {
      string[] splitMessage = message.Split(':');

      switch (splitMessage[0])
      {
        case "MyName": SetName(splitMessage,Connects,connection); break;
      }

public static void SetName(string[] splitMessage, List<PlayerCons> Connects, SomeInterface connection)
    {
      var Id = connection.Id;
      string _name = splitMessage[1];
      Connects.Add(new PlayerCons { _playerName = _name, _connectionId = Id });
      //ошибки:
      //PlayerCons не содержит определение для "_playerName"
      //PlayerCons не содержит определение для "_connectionId"
      //Отсутствует аргумент, соответствующий требуемому формальному параметру "_playerName" из "PlayerConnect.PlayerConnect(string, Guid)".
    }

And in the main file, such an instance of the sheet is created:
public static void Main(string[] args)
    {
      var m_playerCons = new List<PlayerCons>();
    }

I studied the error, but it often refers to a problem with class inheritance, but I don’t inherit anything here, but the error occurs for some reason. How to decide?
PS If I do such an operation directly, not with the help of third-party methods, then everything works, but with the methods there is some kind of error unknown to me.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim, 2016-10-25
@Got_Oxidus

new PlayerCons( _name, Id)
or

new PlayerCons() {PlayerName = _name, ConnectionId = Id}

T
Tsiren Naimanov, 2016-10-26
@ImmortalCAT

You have 1 constructor, with specified overload
add

public PlayerCons(){}
и
new PlayerCons { _playerName = _name, _connectionId = Id }

or write
new PlayerCons( _name, Id)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question