c#如何使"2" *"3" ="6" [英] c# how to make "2"*"3"="6"

查看:94
本文介绍了c#如何使"2" *"3" ="6"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使"2" *"3" ="6";在c#中,请回答我

how to make "2"*"3"="6";in c# please answer me

推荐答案

请参见关于stackoverflow的此问题的答案13 a href ="http://stackoverflow.com/questions/172658/operator-overloading-with-c-extension-methods"> http://stackoverflow.com/questions/172658/operator-overloading-with-c-extension -方法 [ ^ ].类似于该页面中的StringBuilderWrapper,您
可以构建自己的模仿字符串行为的StringWrapper.
实际上,这应该使您非常接近要实现的目标:


See answer 13 to this question on stackoverflow: http://stackoverflow.com/questions/172658/operator-overloading-with-c-extension-methods[^]. Analogous to the StringBuilderWrapper in that page you
can build your own StringWrapper that mimics a strings behaviour.
That should actually get you quite close to what you''re trying to achieve:


StringWrapper sw1 = "2";
StringWrapper sw2 = "3"

String result = sw1 * sw2;
// result == "6"



尽管*运算符的定义将包含在您的解决方案中,但您必须对此进行一些思考.例如,"W" *"3"的结果是什么,它将与"3" *"W"相同吗?不过,您所追求的是可以实现的!

我不太确定为什么您或其他人会需要它,但是也许您可以启发我们解决这个问题.

最好的问候,

-MRB



You''ll have to put some thought into this though what the definition of the * operator will encompass in your solution. Like for instance what is result of "W" * "3" and will it be the same as "3" * "W"? Nevertheless what you are after can be achieved!

I''m not quite sure why you or anybody else would need it, but maybe you can enlighten us on that subject.

Best Regards,

-MRB


您可以使用Convert类的静态方法,例如....
you can use static methods of Convert Class like this....
int v1 = Convert.ToInt32("2");
int v2 = Convert.ToInt32("3");
int ans = v1*v2;

//if you have TextBox here then you can write like...
int v1 = Convert.ToInt32(textBox1.Text);//converting text in to Integer Value
int v2 = Convert.ToInt32(textBox2.Text);//converting text in to Integer Value
int ans = v1*v2;//use to Arithmetic or other Operation
textBox3.Text = Convert.ToString(ans); //to display in third textBox..


这篇关于c#如何使"2" *"3" ="6"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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