gpt4 book ai didi

c# - 如何将对象的实例作为字符串获取?

转载 作者:太空宇宙 更新时间:2023-11-03 17:25:48 25 4
gpt4 key购买 nike

是否有可能获取作为字符串表示形式返回的对象实例,例如“0x12345678”还是“12345678”?

像这样的伪代码:

string myObjectsInstanceAsAString = myObject.instance.ToString();

谢谢

最佳答案

您需要 override ToString() method对于 object type .

public override string ToString(){

// do implementation here
}

MSDN: How to: Override the ToString Method

关于c# - 如何将对象的实例作为字符串获取?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16150106/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com