Click here to Skip to main content
16,010,427 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
how to make "2"*"3"="6";in c# please answer me
Posted
Comments
Manfred Rudolf Bihy 23-May-11 19:16pm    
I'm sure your meant to say: "2" * "3" == "6"

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:


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

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


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
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 23-May-11 19:51pm    
Perfectly understand how can this be done. Elegant. However I would entitled it "Much ado about nothing" :-) My 5 anyway.
--SA
Manfred Rudolf Bihy 23-May-11 21:00pm    
"Much ado about nothing", that just about wraps it up nicely, SA! ;)
Thanks for the vote!
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..
 
Share this answer
 
Comments
Manfred Rudolf Bihy 24-May-11 1:28am    
Reason for my vote of one:
You missed the question. OP wants to use the multiplication operator with string literals. See my solution for on how this can be achieved.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900