我读了on a blog C# 7 将以记录类型为特色
class studentInfo(string StudentFName, string StudentMName, string StudentLName);
但是当我尝试的时候,我得到了这些错误
CS0116 A namespace cannot directly contain members such as fields or methods
CS1022 Type or namespace definition, or end-of-file expected
CS1514 { expected
这应该如何工作?
更新:这是 C# 9 的一个特性 https://devblogs.microsoft.com/dotnet/welcome-to-c-9-0/
最佳答案
更新:
C# 9 now contains record types .
public record Person
{
public string LastName { get; }
public string FirstName { get; }
public Person(string first, string last) => (FirstName, LastName) = (first, last);
}
旧答案:
记录类型(尚未)在 C# 中实现。请参阅官方 GitHub 存储库中的提案:
https://github.com/dotnet/csharplang/blob/master/proposals/records.md
关于c# - 如何声明 C# 记录类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43105895/