12 Replies
I got an assignment to create a nuget package from a class library. So I got this code that opens a text file and make some calculations of characters from the textfile. My question is possible to create a class library that does that. I'm a beginner so bare with me
I want the file path way as the variable
It's definitely possible and you should actually factor your logic out of
Main
anyway. First just add a new class and put the logic in a method on that class, and call that method from Main
You will also want to move the WriteLine and ReadLine out of your new method and keep those in Main
You can pass the path to your new method as an argument to your new methodAlright not sure how I would do that as I trying to get a hold on this coding. Is there any examples?
Well you could start by completing the quick tutorials that teach you the very basics of C#.
$helloworld
You aren't going to get far if you don't know how to create a class and method
Written interactive course https://learn.microsoft.com/en-us/users/dotnet/collections/yz26f8y64n7k07
Videos https://dotnet.microsoft.com/learn/videos
But I'll give you a clue. It will look something like
Okay thanks, 50% chance now that I solve it before going in to extratime
Okay it didn't work for me having the method as public double. Had to change it to public static void
I meant you are supposed to adjust your code for public double, not just copy and paste it straight from Main
Okay should the streamreader be inside those double brackets?
Now I'm really spoon-feeding you and you really should learn to figure out basics for yourself by following tutorials and examples. But it's Monday and I'm feeling fresh and kind.
You shouldn't be using
WriteLine
in your class, it should be agnostic as to how it's results will be used. Then you have something like this:
This way you lose printing all the individual values, but do you really need that? We can work something out for that but it gets more complex. Notice how the logic in your class is independent of how the result is displayed, and how the console app, i.e. the Program
class isn't aware of how gc
is calculated.Thanks a lot. I will look into it more deeper tomorrow. Big up
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.