41 Replies
you need to convert it to a string, which you can do by doing
a.ToString()
that is pretty strange though, you are basically just setting textBox1.Text
to itselfthanks, i totally forgot about that
please stop making additional threads for the same problem
this is the 3rd one
it's a different one
it looks like the same thing z showed you an example of in the last thread
his example didn't apply
int a, b, c;
if (int.TryParse(textBox1.Text, out a) && int.TryParse(textBox2.Text, out b)) {
textBox1.Text = a.ToString();
textBox2.Text = b.ToString();
c = a;
textBox1.Text = b.ToString();
textBox2.Text = c.ToString();
}
_
you can say so in that thread
int a = Convert.ToInt32(textBox1.Text);
int b = Convert.ToInt32(textBox2.Text);
int c;
textBox1.Text = a.ToString();
textBox2.Text = b.ToString();
c = a;
textBox1.Text = b.ToString();
textBox2.Text = c.ToString();
making new threads for every small change makes it hard to follow
which is better
to me, neither
i see no reason to convert them to and from integers if you just want to swap the contents
does it go up?
?
my post
the same people that responded will still be there
leaving them hanging to make a new post just makes it slower for you to get answers
what would be more professional?
remove all the unnecessary conversions
you can swap 2 variables in 3 lines, or even make it a single line if you use a trick with tuples
yes, this is a picture of code
there's an error..
there is indeed
i removed the conversion as you said and got an error
writing code involves understanding the code you're writing
do you know what that error means?
no
you declared a variable but never assigned it a value
in this code a, b, and c are all uninitialized
you probably don't want ints either, because you're working with text
what value should I give it to
I'm swapping numbers
values of text boxes aren't numbers, they're strings
unless you need to do math with them there's no reason to parse them to actual numbers
they can be used for numbers
to solve the "swap 2 numbers" problem you don't actually need to make them numbers, because the problem is really "swap 2 variables"
you only need a single extra variable to solve this problem
which is?
...a single extra variable
it wasn't a trick question
for some reason you make me feel stupid lol
u don't give direct answers
correct
I want to get spoonfed
most people here don't do that
idc about c# I'm learning something else
but I have to cuz of uni
unfortunately that attitude won't get you answers here
better off googling problems like this if you just want to be given the answer
I already solved it, just wanted to do it more professionally but whatever
fwiw,
is the answer i was trying to lead you to
or even shorter
wow that's much simpler
text boxes almost always get converted so I'm used to it