问题描述
我正在开发一个具有 N 层架构的项目。在主函数中生成新对象时出错。我无法提供 car1 的功能。整个文本用红色下划线标出,我收到这些错误“CS1922:无法使用集合初始值设定项初始化类型‘汽车’,因为它没有实现‘System.Collections.IEnumerable’”和“CS0747:无效的初始值设定项成员声明器”。>
using Business.Concrete;
using System;
using Entities.Concrete;
using DataAccess.Concrete.EntityFramework;
static void Main(string[] args)
{
Car car1 = new Car
{
car1.Id = 4,car1.BrandId = 1,car1.ColourId = 2,car1.ModelYear = 1990,car1.Name = "King",car1.DailyPrice = 150,car1.Description = "Best"
};
CarManager carManager = new CarManager(new EfCarDal());
Console.ReadLine();
}
实体\混凝土\汽车.cs
using Core.Entities;
using System;
using System.Collections.Generic;
using System.Text;
namespace Entities.Concrete
{
public class Car : IEntity
{
public int Id { get; set; }
public int BrandId { get; set; }
public int ColourId { get; set; }
public string Name { get; set; }
public int ModelYear { get; set; }
public int DailyPrice { get; set; }
public string Description { get; set; }
}
}
解决方法
在 car1.
中初始化时不需要 {}
访问权限,如下所示:
Car car1 = new Car
{
Id = 4,BrandId = 1,ColourId = 2,ModelYear = 1990,Name = "King",DailyPrice = 150,Description = "Best"
};