A quick question, how do we edit the value of an attribute in an input file?
My prof states that items named, appetizer, entree, and dessert must have values of 0, 1, and 2, when reading the input file, but I am at a loss. I emailed him, but his respond time is crazy long.
51 Replies
What do you mean when you say "an attribute"?
Because that word means something very specific in C#
pause, that's my fault for wrong terminology. i think i am mixing things up
i am simply referring to the items in an input file
"the items in an input file"? You mean the lines?
"an input file" could mean pretty much anything
lemme just send a screnshot
bc i don't mean the full line
they can be read as a byte array, or an array of strings, or one giant string
like this for exmaple
withing the first line, where it says entree
he says it must return an integer value
in this case a value of 1
can you paste the entire file?
in a code block
yes, please allow me a moment
this is the entire input file
appetizer returns value 0, entree returns 1, ans 2 for dessert
ok so its a tab separated CSV
Im guessing
Entree
, Appetizer
and Dessert
should be an enumi honestly didn't even think of that
i felt so stuck too
okay let me try that first, i'll brb
i have a question again
so when the stream reader reads the first part of the line, entree in this case, does it automatically read the enum value with it? he only taught us what enums are but never really implimented them, so i am unsure
google is not helping much
no of course it doesnt
i didn't think so
the file contains the string
"Entree\t28\tPan-Seared Halibut"
the reader is not aware of any enums
so this is the enum i had created
yup, seems fine, other than the name
use PascalCase, and call it something appropriate
like
DishType
i can alter it of course, but i just wanted to make sure the structure was proper
yeah the definition is fine
i have an integer variable named that already so i didn't bc i didn't wanna be confused
or to confused my prof
well its pascal case so it would be fine
one moment
that integer is supposed to map up with your enum, no?
like, literally replace it :p
yes, but that's the thing. I am unsure how to do that because he never truly went over it. like when the reader reads that line and sees "entree" i am unsure how to make have its enum value
i watched a youtube videi for better understanding though
i don't know how to make that apply to input files
you read it as a string
then you parse the string to the correct enum value
Enum.TryParse<T>
is what you need, assuming you are using modern C#
something like this ?
so close, yet so far away š
Entree
would be your variable containing the string value you read from the fileas long as there's hope i'm still willing to learn lol
then would i put the literal value there ? 1 in this case
no
you dont put that anywhere
your file contains the string "Entree", no?
yes it does
so i leave it blank?
wdym you leave it blank
"Entree" will get mapped to
DishType.Entree
by the parse functionlike after the <DishType> is it just <DishType>()
that has the true value
1
:000
that makes way more sense then wtf i was saying
yes
I agree š
i assumed that there a lot of steps i need to take
š
that's the way i'm being taught, so ig i just make things unnecessarily difficult
u break things down easier
well to be fair, its one of me and one of you
true
its always harder to teach multiple students
there's only like 6 ppl total in this class though
idk i just wish he would slow down some
he moves way too fast and apparently with an outdated teaching style
anyways
so look at this code then rq
i did a quick loop thingy
ik it's messed up but i have a question
so im told we need a while look to read the contents of the input file, yes
I would suggest adding
Trim
to the string split options btwTrim ?
what .NET version are you using?
one moment, let me see
it says .NET 6.0
good
okay i can do that, though why would u say trim is better out of curiosity
its not better
I use both
see?
oh ok i though u meant get rid of that entirely
one moment while i fix it pl
I even posted the code verbatim wth
and I said " I suggest adding trim"
ok
so back to my question, in this sense, would i put the enum parse within the while loop ?
like while loop only, or inside the if, or none?
seriously?
sigh
nevermind
thank for your help thus far, but i will figre it out on my own
Just kinda feels like you have no idea whats going on and just throwing code at the problem when you ask a question like that
its like discussing temperatures and basking techniques for cooking, to then ask "yeah so uh do we cook the chiken before or after serving it by the way?"
Think of what is available and known
* outside the while
* inside the while, outside the if
* inside the if
and the answer should be obvious
dawg i started this coding class literally last month. i've expressed how much i am struffling, how intense and unreliable my professor is, and how confusing this all is to me. i understand it can be frustrating and one may lose their patience, but alls i ask for is help. I don't need the attitude or remarks. I simply ask for help, not to feel stupid with every question i ask.
i feel like i am frustrating you, so i will try and get ahold of my prof again and get out of your hair
i will close the post now, i do appreciate the help you've given me thus far though