Assignment
I want the code to show the text file in the visual stuido console however its not working right now, any help?
56 Replies
"show the file", as in show the path to the file, or show the content of the file?
Describe "not working right"
content of the file
its wont show it in the console
Nowhere in your code are you opening the file.
Or printing the file. Or the file path.
Don't take this the wrong way, but have you tried googling "C# read text file"?
i have but im getting even more confused cuz there is multiple ways of doing it and im not sure which one to use and i thought this way would be the simplest
Pick any of them and see if it works
"this way"?
If it doesn't, try another
you are not doing any way at the moment, sir
you have nothing that even attempts to open a file here
all you have is a conditional assignment of a
fileName
variable, and some writingso what should i do to make the user input choose the desired file
Well, the selection you have there would work
You've already done that part
It would result in one path being chosen
You just need to actually open a file at this path
ahhh i see
give me 5 mins
this is where im at now?
still doesnt seem to open the file in console
That should work fine.
does it say anything about error in the console when you run it?
nope there is one warning on line 51 about ex never being used
but the console still opens and immidiately closes
Do the files have... text in them?
indeed
opens and immidiately closes
do you not even get to answer
1 2 or 3
?nope
this is not the main method
are you calling this method from Main?
How are you running
fileChoice()
method?
(should be named FileChoice()
btw)i mean it wont let me run fileChoice but it will let me run filePath in the main
FilePath filePath = new FilePath();
If a method doesn't run... it doesn't run
If you don't call a method, it doesn't run
If you want
fileChoice()
to run, you need to call itit not letting me call it
what do you mean by that
thats not a methodcall
Methods belong to classes
You can't just refer to a method from another class loosely like that
You need either an instance of that class if the method is non-static
also, you called the method
fileChoice
, not FileChoice
Or the class itself if the method is static
See that
Console.WriteLine()
you use a lot? It's class Console
and a static method WriteLine()
FileChoice is a public static void class
No such thing as a void class
Or a static class
i mean method
are you sure?
Incorrect again
fileChoice()
is a static void methodðŸ˜
You don't have a method called
FileChoice()
that clearly says its
fileChoice
i changed it to a capital as visual studio was prompting me too
Okay, but what class is that method declared in?
FilePath
?i want to declare it Program
Then do that?
Declare is where its code is written
you did not write it in program
Currently, you seem to have it declared in its own class
so if you want it in Program, just move it
there definately are static classes, even if not very relevant here :p
derp
i shall get back to you
Why not make the program get all files from the directory and then make a dictionary and then generate the selection UI.
:SCcrawl:
ok so i was being silly
I called in in the program calls by FilePath.FileChoice();
and it works