C# 如何解决错误不包含-new to C的定义#

C# 如何解决错误不包含-new to C的定义#,c#,.net-core,C#,.net Core,在使用nodejs/typescript编程之后,我开始学习c 我遇到了以下错误: cs(22,50):错误CS1061:“Book”不包含“name”的定义,并且找不到接受类型为“Book”的第一个参数的可访问扩展方法“name”(是否缺少using指令或程序集引用?) 这是我的课 using System; using System.Collections.Generic; namespace GradeBook { public class Book {

在使用nodejs/typescript编程之后,我开始学习c

我遇到了以下错误:

cs(22,50):错误CS1061:“Book”不包含“name”的定义,并且找不到接受类型为“Book”的第一个参数的可访问扩展方法“name”(是否缺少using指令或程序集引用?)

这是我的课

using System;
using System.Collections.Generic;

namespace GradeBook
{
    public class Book
    {
        // this is how we generate a constructor in c#
        public Book(string name)
        {
            grades = new List<double>();
            Name = name;
        }

        public void AddGrade(double grade)
        {
            grades.Add(grade);
            Console.WriteLine($"A new added grade: {grade:N2}");
        }

        public Stats GetStats()
        {
            var result = new Stats();
            result.Average = 0.0;
            result.High = double.MinValue;
            result.Low = double.MaxValue;

            foreach (var grade in grades)
            {
                // log hightest grades
                result.High = Math.Max(grade, result.High);
                // log lowest grades
                result.Low = Math.Min(grade, result.Low);
                result.Average += grade;
            }

            result.Average /= grades.Count;

            return result;
        }

        // its no longer a variable it is now called field in c#
        private List<double> grades;
        public string Name;
    }
}

字段名在C#中区分大小写,因此在此行中:

Assert.Equal("My Book", book1.name);
名称
应为
名称

Assert.Equal("My Book", book1.Name);

实际上,您的代码中有一些地方需要更正。

哪一行代码会引发该异常?
Assert.Equal("My Book", book1.Name);