Need help finishing a project but I have no clue how to go about it
BlazeBin - avzymzbsntmm
A tool for sharing your source code with the world!
145 Replies
If anyone can help, please tag me. i want to go to bed because I have a final in 7 hours
$help
How to get the best help :catpog:
Make a post in #help or one of the topic channels under Development.
Avoid asking
:catthinking: Can anybody help me?
:catthinking: Has anyone used XYZ?
:catthinking: Why doesn't my code work?
C# is a big area! No one knows they can help unless you tell them about the small area you're trying to work in.
Explain what you are doing, and potentially why for as much context as possible. Avoid screenshots where possible, share code directly in Discord. Type
$code
into chat to learn how to post code.
See https://www.nohello.net and https://dontasktoask.com if you want common help chat room etiquette.We are not going to write code for you. That is your job.
We can however point you in the right direction.
i asked for help, not for someone to do my dirty work. I just want to know if my current code is fine, and need direction making a search engine, and saving user input to a csv file.
MODiX#0152
How to get the best help
Make a post in <#1007030034902548540> or one of the topic channels under Development.
Avoid asking Can anybody help Has anyone used Why doesn't my code work?
C# is a big area! No one knows they can help unless you tell them about the small area you're trying to work in.
Explain what you are doing, and potentially why for as much context as possible. Avoid screenshots where possible, share code directly in Discord. Type
$code
into chat to learn how to post code.
See https://www.nohello.net and https://dontasktoask.com if you want common help chat room etiquette.Quoted by
<@203166497198047232> from #Need help finishing a project but I have no clue how to go about it (click here)
React with ā to remove this embed.
We can't help without knowing what to help with.
You just said help and linked code.
okay i apologize
I would not use any cloud service to save a file your project depends on though
assuming that path is for OneDrive
you may get some weird errors because of syncing
Your properties are not following the C# conventions
Also you can use auto-properties
No need to write backing-fields
in this case
Properties should use PascalCase
So
name
becomes Name
or like lastname
becomes LastName
okay so the reason I do properties like that is because of my instructor. It's like his way of seeing that we aren't using ChatGPT
Lmfao
im so serious
Interesting reasoning by your instructor
Note that private backing fields should use camel case but with _ prefix
_lastName
So it will become like this
for private properties, he asks for lowercasename
:distilld_look:
i dont know. i wish i could tell you why we do things the way we do
Alright
he tells us that we should only care if it shows errors
and the lowercase names dont get errors sooo
I mean, sure.
It just helps to follow the official coding convention.
Makes it more readable.
but anyway, with my code as is right? why is it not saving the data to the csv
?
What happens when you call UpdateCsvFile?
Note that if you send the executable to your professor, it will fail to read the csv file due to being absolute path which is not shared.
You write to relative path, meaning current working directory of your program.
And you read from OneDrive/Documents path
I can pretty much bet that it is reading the wrong file.
well at the beginning i set a string filePath = Electronics.csv
does that not like open direct files named that?
No, it just means relative.
If you do not specify an absolute path, like
C:/Foo/myfile.txt
it'll be relativei do apologize if my questions are stupid asf lol. i suck at this class
like actually.
sittin 70% rn with a final tomorrow
Relative meaning current workint directory.
Everyone "suck" in the beginning.
That's why you learn.
yeah i know. im trying lol
i like web dev better than C# to be honest
I mean, you seem to be taught C# by a hack, so
Reverse for me š
Web ecosystem is way too complicated for it to be fun.
You'd like it much more were you allowed to use autoproperties lol
auto prop meaning the get; set;?
Yes
$getsetdevolve
can be shortened to
can be shortened to
can be shortened to
can be shortened to
would it have made my code shorter?
Does the below look shorter than the above?
because honestly iāve been using Stack and other things to try and help but i canāt comprehend it
i was not thorough with my question, i meant like would it have made my whole project shorter. like my main program, since i only have 2 classes
not a single project we did in the class required more than 2 classes
Would have made your
electronics
shorterokay so updatecsv is supposed to save it to my file, did i do something wrong there?
No, everything seems fine there
okay so itās just the path thatās messing up things?
what do you suggest that i do with my file path? do i direct input a path? or keep it relative and change the direct path in the methods?
Just keep it relative
That's always the easiest
Relative for sure!
okay so when i use only relative, do i replace it to be File.ReadAllLines(filePath);
instead of
Files.ReadAllLines(Direct Path);?
also how do i go about a search engine?
never done so.
Wdym with a search engine?
^
go to the requirements page and in there
he wants a search engine
for the products input by the user
like to be able to search what is in the file
All it says is "should be able to search for an item"
That's quite different from making a search engine
is that not technically a search engine type of thing?
That's like calling a stick figure a magnificent work of art
:p
welp š«
Anyways, you have a few options. What parameters do you want to search on? Should it be possible to get more than one result from a search?
way to make me feel dumb
šš
the comparison was crazy but yes, i assume so because thereās different types of ipads
and laptops
and other things
If you only allow searching by name and returning the first item that matches the search, then it's literally 1 line of code
ok so if i wanted to search just iPads in general
all ipads show up?
or just the words āiPadā shows up alone?
i would assume he wants it to be like a website because itās supposed to be inventory
Well, your search domain would reasonably be your list of products
And your return should reasonably then be zero or more products that match the search query
ok ok 1 sec
But since your product has 3 properties you might want to search in (name, brand, model)...
let me update that link and send a new one to see what i need to finish other than the search thingy
I'm on my morning commute so reading large swathes of code rn will be difficult
BlazeBin - jppsdnhdrzsd
A tool for sharing your source code with the world!
its okay, one of the other guys might be able to help too
Can't you go over your own code and compare it with the requirements?
That seems like the easiest solution
yeah, but it wouldn't hurt for someone to skim through, and tell me if theres slight errors in my coding
and i still haven
haven't gotten an answer to the file path being correct or incorrect
but from what i can see, the only thing that needs to be done is the search for item
Seems fine to me at a glance
I find it odd that you can call save CSV from the menu when adding an item also calls it behind the scene
And same for loading
Ok so do the search
I'll give you a hint: all collections have a method called .Where
i have no clue. i thought adding an item would already by default list the item.
It returns zero or more items from that collection that match the given predicate
and i thought the UpdateCSV would just collect the data
because thats its job
"collect the data"?
but it was eitherthe file path or something else, because the program runs, but does not save to file
like save
The data is already collected, its your static list, no?
Well with just a filename in your code, the location of the file will be next to the executable
That's likely project/bin/net8.0/debug/
Look there and see if you can find a file
like look in my file explorer for it?
Sure
Seems like a good way to verify that it works
do not have a project/bin/net8.0/debug/
What's in your project root then?
wait actually there is a folder, but itās empty lol shoot i donāt know why it didnāt show up
itās a empty bin file
folder**
Bin is entirely empty?
How are you running your program?
bin>debug>
okay the net8.0 is there now wtf
itās there now
start your program once
and just to be sure, you're 100% sure you are in the right project directory now right?
yes
100%
okay, now while the program is running, look in that folder again
net8.0 is still empty
not possible
1 sec
right?
hold on let me restart my computer
itās been on for hours
see if it stop fuckin with me
itās boiling a little
add this to the top of your
Main
Console.WriteLine(Directory.GetCurrentDirectory());
you have not actually shown any paths so I cant tellhey hey it worked
the reset got it to pop up the stuff
i did have file syncing issues
because of OneDrive which is a source control we use
O_O
itās for schooling
onedrive as source control... by probably syncing the entire repos folder
including build artifacts
jfc thats nightmare fuel
i do have a whole folder of repos
lol
thats fine
but not using git and .gitignore files to manage it is not fine š
anyways
well i have no say here
if you open that folder up, now can you see your csv file?
iām just a student
š
yes i can
Electronics.csv
good
ok so only the search left then
okay so my ReadData is supposed to realistically load my data from the csv right?
yes?
okay yeah iāll do that search engine and comeback real quick and let you know if itās finally fully functional.
okidoki
I go eat breakfast š
when i tell you ive been working on this project for 5 hours.. lol
enjoy
thats absolutely fine, we all gotta start somewhere
oh wait
private static Electronics? SearchEngine(string? name)
{
return electronicsList.FirstOrDefault(p => p.name.Equals(name, StringComparison.OrdinalIgnoreCase));
}
does that look right at all
yes but also no š
fuck
for one, it only returns zero or one entries
it also requires you to know the exact name
and it also only searches on the name, not on brand or model
well i might just go for name only and say fuck him
because i have to be up in 5 hours
for a final
i canāt keep staying up lol i need to end this madness
oh wait error handling
he did say he would attempt to break the program
on search in particular or overall?
search
well given that implementation of search, I dont see much that could go wrong
at best he can make a malicious string, but that wont do much
is there a better way you wouldāve did the method as opposed to what i did?
well, I'd fix the three issues I listed above
with something like this:
yeah i have never wrote nothing like that lol
only the stringcomparison
now it returns zero or more, doesnt require exact name, and searches on all three properties
whatās with the x.
its a lambda
in this case its a predicate, an anonymous function that returns a bool
basicly
private static bool ThePredicate(Product x)
but its written as x => ...
it knows the type of x
because it knows the type of list
whew my brain is not braining
does it help if we give it a longer name?
yeah i got that now
okay doin a quick test to see if the program runs as it should
@Pobiega i donāt know what i did wrong, but the program is not functioning correctly lol i think i messed up the search part because it no longer is a method technically
huh
can you show the errors?
attempt #2
You are calling the method without passing in the search parameter (query)
Also, $screenshot
If you want to share code, please copy and paste the code into a markdown code block in your discord post, or paste the code into https://paste.mod.gg/ and share a link to it in your discord post.
If want to share a screenshot, please do not take a photo of your computer screen with your phone or camera. Instead see https://www.take-a-screenshot.org/ for how to take a screen capture on your device. You may want to crop the image before pasting it into your discord message.
oh sorry
don't modify code while running
and you have 2 implementations of
SearchEngine()
it seemsit suggested that i made add that throw exception in there
sure
this logic needs to go there then
All the other methods you call from your menu handle user input inside the method, so perhaps its best to do the same for search
thats originally what it was essentially
okay so case 3:
(Method)
break;
and redo the method?
Method();
And fix up your method so it handles both input and output
yeah thatās what i meant lol just exhausted
yeah cause the method has the wrong signature
if it handles input/output itself, it should be
void SearchEngine();
not returning anything or taking anything indo i add a field for query? because thatās the only error right now
no, you handle all that inside the method, just like with the other methods
dunno if its the lack of sleep on your end, but your existing code was pretty clean and handled all this nicely
iāve just been up about 18 hours and have to be up in 6
Go to sleep
iām going to bed now
sleep well
thank you guys for the help.