public struct MyStruct {
  public string s;
  public int length;

  public static implicit operator MyStruct(string value) {
    return new MyStruct() { s = value, length = value.Length };
  }

}

Example:

MyStruct myStruct = "Lol";
Console.WriteLine(myStruct.s);
Console.WriteLine(myStruct.length);

Output:

Lol
3

 

相关文章:

  • 2021-11-23
  • 2021-11-17
  • 2021-09-21
  • 2021-11-23
  • 2021-11-23
猜你喜欢
  • 2021-11-23
  • 2021-11-23
  • 2021-08-31
  • 2021-07-05
  • 2021-10-07
  • 2022-12-23
相关资源
相似解决方案