【发布时间】:2019-01-15 17:24:37
【问题描述】:
我无法从 Homecontrollers 操作方法调用新的 Human 对象。
var employee = new Human { id = 1, name = "home index" , isAuth = isAuth,token="null"};
这是我的模特
namespace WebApplication3.Models
{
public class Human
{
public Human(int id, string name, string isAuth, string token)
{
this.id = id;
this.name = name;
this.isAuth = isAuth;
this.token = token;
}
【问题讨论】:
-
应该像 new Human( id = 1, name = "home index" , isAuth = isAuth,token="null");构造函数使用第一轮而不是花括号。
-
或者添加一个空的构造函数(前提是那些属性是公共的)
-
@Gaurav,您不能使用“=”来命名参数。
var employee = new Human (id: 1, name: "home index", isAuth: isAuth, token: "null");或var employee = new Human (1, "home index", isAuth, "null");