如何修复一个不断通知我没有使用抽象关键字的错误,因此我需要声明一个主体
本文关键字:一个 错误 声明 主体 关键字 何修复 通知 抽象 | 更新日期: 2023-09-27 18:25:09
using System;
using System.IO;
using System.Text;
class Planner
{
public string firstName { get; set; }
public string lastName { get; set; }
public DateTime dateTime { get; set; }
}
class exe
{
public static void Main(string[] args)
{
List<Planner> t = new List<Planner>();
FileStream fs = new FileStream("Scheduler.txt",
FileMode.Open,FileAccess.Read);
StreamReader sr = new StreamReader(fs)
{
string line = string.Empty;
while ((line = sr.ReadLine()) != null)
{
string[] lines = line.Split(' ').ToArray();
t.Add(new Planner() { firstName = lines[0], lastName = lines[1],
dateTime = DateTime.ParseExact("MM/dd/yyyy hh:mm:ss tt",
lines[2] + lines[3], CultureInfo.InvariantCulture) });
}
}
t = t.OrderBy(x => x.dateTime).ToList<Planner>()
}
}
在C#3.0
中引入了自动实现的属性。如果你使用的是3.0以下的版本,你需要像这样的属性backup field
-
private string firstName;
public string FirstName
{
get
{ return firstName; }
set
{ firtName = value; }
}
来自MSDN-
在C#3.0及更高版本中,自动实现的属性使当不需要额外的逻辑时,属性声明更简洁在属性访问器中。它们还允许客户端代码创建对象。当您将属性声明为自动时,编译器会创建一个私有的匿名支持字段只能通过属性的get和set访问器进行访问。