❔ C# Will not write to txt file
Not to sure what I did wrong as this is the first time I'm trying this. The code runs just gives (process 32508) exited with code 0.
https://paste.mod.gg/duanwieezrrk/0
BlazeBin - duanwieezrrk
A tool for sharing your source code with the world!
56 Replies
You're not using the streamwriter
You're writing to the console
can you point out where it is writing to console?
ohhh so i need a new set of write lines for the print func that say streamwriter
gotcha
it's never entering this if
That too, yeah
It's trying to compare that char with a boolean
Im not seeing why its trying to compare with a boolean?
Option != 'Y'
This results in a booleanyes
char.Equals doesn't have an overload for what you want
a.Equals(b)
compares char a
with char b
So 'a'.Equals(false)
will try comparing char 'a'
with boolean false
Isn't that
char
the type and not an instance?honestly im not sure. im still trying to learn this.
So to fix would i change char to boolean or the option part to a char?
char
is a keyword in C#you can do
char.Equsl(obj1, obj2)
or Option.Equals(ob1)
Yeah, but that's not what the code shown is doing
yeah
Does that even compile?
yes
cause
StringComparison.OrdinalIgnoreCase
is 5it compiled before i changed the console bits under stream writer to streawriter
Oh it's just treating the StringComparison like another object
Equals(object a, object b)
yeah
So this code is clearly not doing what is intended 🙂
yes lol
i just need it to see if its y or n make it upper case then do what the y or n option is
StringComparison in char Equality is also a red flag
there is no overload
for char equality
and this also brings up another question. if the y/n is not working is the m/w not working also?
i tested your code and the txt is empty
so yes
okat testing the code rn for the streamwriter problem. after that im still not sure how to fix the boolean comparisin prob
you can do:
or
Program does not contain a static 'Main' method suitable for an entry point
its saying that
what did you change
BlazeBin - avehyhvvntnd
A tool for sharing your source code with the world!
why are u passing a StreamWriter in the main as a parameter?
Was about to ask
because it did this - i sec
what you shared before was correct
you just need to correct char comparison
and streamwriter
cause you are calling a method that prints to console
not to file
BlazeBin - yumcdvyzoegl
A tool for sharing your source code with the world!
si i changed the colsole to streamwriter and it was red squiogillys eveerywhere
Because you're trying to use those methods as static
cause your variable is outputefile
Use the
StreamWriter
you instantiateddon't use it as Type
of pute output file there
there we go that makes sense
okay now for the if statements. when you say obj1 obj 2 is it comparing ob1 to obj 2?
Yes
i understand what you want to do, with OrdinalIgnoreCase, but that only works for strings, there is no overload in char.Equals that takes that argument, you just compare chars. That's it
so is obj 1 or obj 2 the master that is the one being compared too
They're... just being compared
okay let me try that 1 min
is that right?
Yep
thankyou
I'm surprised this is valid code
since
char.Equals(obj1, obj2)
evaluates object?
it's valid, albeit wrongHenkypenky#4865
REPL Result: Success
Console Output
Compile: 561.552ms | Execution: 64.937ms | React with ❌ to remove this embed.
Henkypenky#4865
REPL Result: Success
Console Output
Compile: 511.944ms | Execution: 25.421ms | React with ❌ to remove this embed.
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.