Rectangle.FromString() [英] Rectangle.FromString()

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

问题描述

我仍然在C#周围寻找方向,我不确定什么是可能的,而不是

可能。有没有办法做相当于


Rectangle r = new Rectangle();

r.FromString(anotherRectangle.ToString());


并假设没有,小组会建议我用FromString方法创建我自己的

Rectangle类或覆盖ToString给予

更易解析的东西,或者是什么?


谢谢,


Andrew

解决方案

安德鲁,


你别无选择,只能建立自己的结构,因为你不能
派生自.NET中的结构。


当然,这意味着你不能使用矩形结构

,其中使用了常规的Rectangle结构。


我很好奇你为什么要这样做。你要求更多的东西可以解析,但是,持久化到字符串并从那个相同的字符串中获取值的方法已经存在。你想做什么?


希望这会有所帮助。

-

- Nicholas Paldino [.NET / C#MVP ]

- mv*@spam.guard.caspershouse.com

" Andrew McLellan" <一个**** @ cix.co.uk>在消息中写道

news:e


*************** @ tk2msftngp13.phx.gbl ... < blockquote class =post_quotes>我仍然在C#周围寻找方向,我不确定什么是可能的,而不是
可能。是否有任何方法可以做相当于

Rectangle r = new Rectangle();
r.FromString(anotherRectangle.ToString());

并假设小组是否会建议我使用FromString方法创建自己的
Rectangle类,或者覆盖ToString以使某些东西更易于解析,或者是什么?
谢谢,

Andrew



Nicholas Paldino [.NET / C#MVP]写道:

你别无选择,只能创建自己的结构,因为你不能从.NET中的结构派生出来。

当然,这意味着你不能''使用你的矩形结构,使用常规的矩形结构。




我认为在

之外实现这个功能会更好矩形结构(显然)也没有新的Rectangle。我在这里假设是
,当然,所讨论的功能受到限制

可以从外部完成相当简单的事情,比如字符串

你想要的转换。在这种情况下,我认为这将是一个更好的方法

有一个RectangleStringConverter或者介绍你自己的

不可互换的矩形替换。

Oliver Sturm

-

提供专家编程和咨询服务

参见 http://www.sturmnet.org (尝试/博客)


I''m still finding my way round C# and am not sure what is possible and not
possible. Is there any way to do the equivalent of

Rectangle r = new Rectangle();
r.FromString(anotherRectangle.ToString());

and assuming there isn''t, would the panel recommend I create my own
Rectangle class with a FromString method or override the ToString to give
something a bit more parsable, or what?

Thanks,

Andrew

解决方案

Andrew,

You have no choice but to create your own structure, since you can''t
derive from structures in .NET.

Of course, this means that you couldn''t use your rectangle structure
where the regular Rectangle structure is used.

I am curious why you want to do this. You ask for something more
parsable, and yet, the methods to persist to a string and get the values
from that very same string are already there. What are you trying to do?

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Andrew McLellan" <an****@cix.co.uk> wrote in message
news:e


***************@tk2msftngp13.phx.gbl...

I''m still finding my way round C# and am not sure what is possible and not
possible. Is there any way to do the equivalent of

Rectangle r = new Rectangle();
r.FromString(anotherRectangle.ToString());

and assuming there isn''t, would the panel recommend I create my own
Rectangle class with a FromString method or override the ToString to give
something a bit more parsable, or what?

Thanks,

Andrew



Nicholas Paldino [.NET/C# MVP] wrote:

You have no choice but to create your own structure, since you can''t derive from structures in .NET.

Of course, this means that you couldn''t use your rectangle structure where the regular Rectangle structure is used.



I think it would be better to implement this function outside of the
Rectangle structure (obviously) and also without a new Rectangle. I''m
assuming here, of course, that the functionality in question is restricted
to fairly simple stuff that can be done from the outside, like the string
conversion you want. In that case I think it would be a better approach to
have a RectangleStringConverter or something than to introduce your own
non-interchangable Rectangle replacement.
Oliver Sturm
--
Expert programming and consulting services available
See http://www.sturmnet.org (try /blog as well)


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

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