如何撤消.ToString()调用 [英] How to reverse a .ToString() call

查看:38
本文介绍了如何撤消.ToString()调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C#中的每个对象都有可能以ToString()的形式流传输到字符串.给定最初生产的琴弦,是否有一个衬板可以逆转该过程?

Each object in C# has the potential to be streamed to a string as ToString(). Is there a one liner that would reverse the process given the string originally produced?

所以:

var stringSomeObject = SomeObject.ToString();

然后反转:

var someObjectFromToString = ??????.FromString(stringSomeObject);

推荐答案

给定最初产生的琴弦,是否有一个衬套可以逆转该过程?

Is there a one liner that would reverse the process given the string originally produced?

不.每个类型都可以选择以任何方式实现 ToString().这样就不可能随意往返该值.

No. Every type has the option of implementing ToString() in any way is desires. This makes it impossible to arbitrarily round trip the value.

往返对象之间的往返传递通常通过框架对对象序列化的支持来处理./a>

Round tripping objects to and from some other representation is typically handled via the framework's support for Object Serialization.

框架中的特定类型确实按照处理该问题的特定模式来实现方法.许多默认值类型( Int32 Double 等)实现了 .Parse .TryParse 方法,可用于从字符串往返".但是,这是必须针对每种类型实现的,不适用于任意类型.

Specific types within the Framework do implement methods following specific patterns which handle this, however. Many of the default value types (Int32, Double, etc) implement a .Parse and .TryParse method which can be used to "round trip" from a string. This is something that has to be implemented per type, however, and does not work on arbitrary types.

这篇关于如何撤消.ToString()调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆