Как инициализировать структуру?

Какой член я должен реализовать в моей произвольной структуре, чтобы сделать возможным следующее присваивание:

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");

Как это должно быть сделано?

53
задан Servy 9 March 2016 в 04:36
поделиться