這是正確的嗎?如何實例化新的結構對象?
//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