这是正确的吗?如何实例化新的结构对象?
//Structure
public struct Shape
{
public string mShape;
public int mSide;
public Shape(/*initial sides parameter*/ int sSide, string sShape)
{
mShape = sShape;
mSide = sSide;
}
}
//more code here.... but no need to post.
//Instantiate new Shape structure object
myShape = new Shape(/*Sides integer value*/ ,sShape);
//How to Add the additional parameter to construct the object?
从丑陋的编码习惯和公共领域的公寓这看起来对我来说很好。你是什么意思的额外参数? – CodesInChaos 2010-10-14 19:48:16
您的结构应该是不可变的(将所有字段标记为只读和/或将字段封装在没有setter的属性中)。 – dtb 2010-10-14 19:57:52
“结构对象”是c#中的一个矛盾, – 2010-10-14 20:39:04