我應該在任意的結構實現什麼成員作如下分配可能:如何初始化結構?
public struct MyStruct {
String s;
Int length;
}
MyStruct myStruct = new MyStruct { s = "Hello", length = 5 };
// Now, I want the following code to set the 's' to "Lol" and the
// length to 3 (length of "Lol"). The second part should be done
// automatically.
myStruct = "Lol"; // Or myStruct = String("Lol");
應該如何進行?
請不要製作可變結構。 http://stackoverflow.com/questions/441309/why-are-mutable-structs-evil – Ani 2010-12-12 02:25:57
'字符串已經知道它們的長度。你爲什麼需要這樣的結構? – 2010-12-12 02:31:51
@Karl Knechtel:我認爲這是一個顯示原理的例子。顯示的代碼甚至沒有編譯... – Guffa 2010-12-12 02:44:56