生成对象时出现错误

问题描述

我正在开发一个具有 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"
        };

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...