更新时间:2023-02-15 20:10:41
我已经遇到这个问题很多次也和最终使用的接口。
I've come across this issue a lot of times too and ended up using interfaces.
我想放弃的想法,C#是任何形式,甚至的C演变++是很重要的。他们共享几乎相同的语法两种不同的语言。
I think it's important to drop the idea that C# is any form, or even an evolution of C++. They're two different languages that share almost the same syntax.
我通常前preSSconst正确性在C#中定义一个类的只读视图:
I usually express 'const correctness' in C# by defining a read-only view of a class:
public interface IReadOnlyCustomer
{
String Name { get; }
int Age { get; }
}
public class Customer : IReadOnlyCustomer
{
private string m_name;
private int m_age;
public string Name
{
get { return m_name; }
set { m_name = value; }
}
public int Age
{
get { return m_age; }
set { m_age = value; }
}
}