Search
Get Started
C
C#
•
2y ago
Shovel
help with this code c# windows forms
how do i make it work
?
C#
Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,010
Members
View on Discord
Was this page helpful?
Yes
No
R
reflectronic
•
5/15/24, 3:07 AM
you need to convert it to a string
, which you can do by doing
a.ToString()
a.ToString()
R
reflectronic
•
5/15/24, 3:07 AM
that is pretty strange though
, you are basically just setting
textBox1.Text
textBox1.Text
to itself
R
reflectronic
you need to convert it to a string, which you can do by doing `a.ToString()`
S
Shovel
OP
•
5/15/24, 3:16 AM
thanks
, i totally forgot about that
J
Jimmacle
•
5/15/24, 3:23 AM
please stop making additional threads for the same problem
J
Jimmacle
•
5/15/24, 3:23 AM
this is the 3rd one
J
Jimmacle
please stop making additional threads for the same problem
S
Shovel
OP
•
5/15/24, 3:27 AM
it
's a different one
J
Jimmacle
•
5/15/24, 3:28 AM
it looks like the same thing z showed you an example of in the last thread
J
Jimmacle
•
5/15/24, 3:28 AM
S
Shovel
OP
•
5/15/24, 3:29 AM
his example didn
't apply
S
Shovel
OP
•
5/15/24, 3:29 AM
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
(
)
;
}
S
Shovel
OP
•
5/15/24, 3:30 AM
_
S
Shovel
his example didn't apply
J
Jimmacle
•
5/15/24, 3:30 AM
you can say so in that thread
S
Shovel
OP
•
5/15/24, 3:30 AM
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
(
)
;
J
Jimmacle
•
5/15/24, 3:30 AM
making new threads for every small change makes it hard to follow
S
Shovel
OP
•
5/15/24, 3:30 AM
which is better
J
Jimmacle
•
5/15/24, 3:30 AM
to me
, neither
J
Jimmacle
•
5/15/24, 3:30 AM
i see no reason to convert them to and from integers if you just want to swap the contents
J
Jimmacle
you can say so in that thread
S
Shovel
OP
•
5/15/24, 3:30 AM
does it go up
?
J
Jimmacle
•
5/15/24, 3:30 AM
?
S
Shovel
OP
•
5/15/24, 3:31 AM
my post
J
Jimmacle
•
5/15/24, 3:31 AM
the same people that responded will still be there
J
Jimmacle
•
5/15/24, 3:31 AM
leaving them hanging to make a new post just makes it slower for you to get answers
J
Jimmacle
i see no reason to convert them to and from integers if you just want to swap th...
S
Shovel
OP
•
5/15/24, 3:32 AM
what would be more professional
?
J
Jimmacle
•
5/15/24, 3:32 AM
remove all the unnecessary conversions
J
Jimmacle
•
5/15/24, 3:33 AM
you can swap 2 variables in 3 lines
, or even make it a single line if you use a trick with tuples
J
Jimmacle
remove all the unnecessary conversions
S
Shovel
OP
•
5/15/24, 3:34 AM
J
Jimmacle
•
5/15/24, 3:35 AM
yes
, this is a picture of code
S
Shovel
OP
•
5/15/24, 3:35 AM
there
's an error
.
.
J
Jimmacle
•
5/15/24, 3:35 AM
there is indeed
S
Shovel
OP
•
5/15/24, 3:35 AM
i removed the conversion as you said and got an error
J
Jimmacle
•
5/15/24, 3:36 AM
writing code involves understanding the code you
're writing
J
Jimmacle
•
5/15/24, 3:36 AM
do you know what that error means
?
S
Shovel
OP
•
5/15/24, 3:36 AM
no
J
Jimmacle
•
5/15/24, 3:36 AM
you declared a variable but never assigned it a value
J
Jimmacle
•
5/15/24, 3:37 AM
in this code a
, b
, and c are all uninitialized
J
Jimmacle
•
5/15/24, 3:37 AM
you probably don
't want ints either
, because you
're working with text
S
Shovel
OP
•
5/15/24, 3:37 AM
what value should I give it to
S
Shovel
OP
•
5/15/24, 3:37 AM
I
'm swapping numbers
J
Jimmacle
•
5/15/24, 3:38 AM
values of text boxes aren
't numbers
, they
're strings
J
Jimmacle
•
5/15/24, 3:38 AM
unless you need to do math with them there
's no reason to parse them to actual numbers
S
Shovel
OP
•
5/15/24, 3:38 AM
they can be used for numbers
J
Jimmacle
•
5/15/24, 3:38 AM
to solve the
"swap 2 numbers
" problem you don
't actually need to make them numbers
, because the problem is really
"swap 2 variables
"
J
Jimmacle
•
5/15/24, 3:39 AM
you only need a single extra variable to solve this problem
S
Shovel
OP
•
5/15/24, 3:40 AM
which is
?
J
Jimmacle
•
5/15/24, 3:40 AM
.
.
.a single extra variable
J
Jimmacle
•
5/15/24, 3:40 AM
it wasn
't a trick question
S
Shovel
OP
•
5/15/24, 3:40 AM
for some reason you make me feel stupid lol
S
Shovel
OP
•
5/15/24, 3:41 AM
u don
't give direct answers
J
Jimmacle
•
5/15/24, 3:41 AM
correct
S
Shovel
OP
•
5/15/24, 3:41 AM
I want to get spoonfed
Next page
help with this code c# windows forms - C#