C
C#ā€¢7mo ago
Dread

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
Dread
DreadOPā€¢7mo ago
If anyone can help, please tag me. i want to go to bed because I have a final in 7 hours
Buddy
Buddyā€¢7mo ago
$help
MODiX
MODiXā€¢7mo ago
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.
Buddy
Buddyā€¢7mo ago
We are not going to write code for you. That is your job. We can however point you in the right direction.
Dread
DreadOPā€¢7mo ago
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
MODiXā€¢7mo ago
MODiX#0152
How to get the best help catpog Make a post in <#1007030034902548540> or one of the topic channels under Development. Avoid askingcatthinking Can anybody help catthinking Has anyone used 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.
React with āŒ to remove this embed.
Buddy
Buddyā€¢7mo ago
We can't help without knowing what to help with. You just said help and linked code.
Dread
DreadOPā€¢7mo ago
okay i apologize
SG97
SG97ā€¢7mo ago
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
Buddy
Buddyā€¢7mo ago
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
Dread
DreadOPā€¢7mo ago
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
Buddy
Buddyā€¢7mo ago
Lmfao
Dread
DreadOPā€¢7mo ago
im so serious
Buddy
Buddyā€¢7mo ago
Interesting reasoning by your instructor Note that private backing fields should use camel case but with _ prefix _lastName So it will become like this
private string _lastName;

public string LastName
{
get => _lastName;
set => _lastName = value;
}
private string _lastName;

public string LastName
{
get => _lastName;
set => _lastName = value;
}
Dread
DreadOPā€¢7mo ago
for private properties, he asks for lowercasename
Buddy
Buddyā€¢7mo ago
:distilld_look:
Dread
DreadOPā€¢7mo ago
i dont know. i wish i could tell you why we do things the way we do
Buddy
Buddyā€¢7mo ago
Alright
Dread
DreadOPā€¢7mo ago
he tells us that we should only care if it shows errors and the lowercase names dont get errors sooo
Buddy
Buddyā€¢7mo ago
I mean, sure. It just helps to follow the official coding convention. Makes it more readable.
Dread
DreadOPā€¢7mo ago
but anyway, with my code as is right? why is it not saving the data to the csv ?
Buddy
Buddyā€¢7mo ago
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.
Dread
DreadOPā€¢7mo ago
well at the beginning i set a string filePath = Electronics.csv does that not like open direct files named that?
Buddy
Buddyā€¢7mo ago
No, it just means relative. If you do not specify an absolute path, like C:/Foo/myfile.txt it'll be relative
Dread
DreadOPā€¢7mo ago
i do apologize if my questions are stupid asf lol. i suck at this class like actually. sittin 70% rn with a final tomorrow
Buddy
Buddyā€¢7mo ago
Relative meaning current workint directory. Everyone "suck" in the beginning. That's why you learn.
Dread
DreadOPā€¢7mo ago
yeah i know. im trying lol i like web dev better than C# to be honest
Angius
Angiusā€¢7mo ago
I mean, you seem to be taught C# by a hack, so
Buddy
Buddyā€¢7mo ago
Reverse for me šŸ™‚ Web ecosystem is way too complicated for it to be fun.
Angius
Angiusā€¢7mo ago
You'd like it much more were you allowed to use autoproperties lol
Dread
DreadOPā€¢7mo ago
auto prop meaning the get; set;?
Angius
Angiusā€¢7mo ago
Yes $getsetdevolve
MODiX
MODiXā€¢7mo ago
class Foo
{
private int _bar;

public int GetBar()
{
return _bar;
}

public void SetBar(int bar)
{
_bar = bar;
}
}
class Foo
{
private int _bar;

public int GetBar()
{
return _bar;
}

public void SetBar(int bar)
{
_bar = bar;
}
}
can be shortened to
class Foo
{
private int _bar;

public int GetBar() => _bar;

public void SetBar(int bar) => _bar = bar;
}
class Foo
{
private int _bar;

public int GetBar() => _bar;

public void SetBar(int bar) => _bar = bar;
}
can be shortened to
class Foo
{
private int _bar;
public int Bar {
get { return _bar; }
set { _bar = value; }
}
}
class Foo
{
private int _bar;
public int Bar {
get { return _bar; }
set { _bar = value; }
}
}
can be shortened to
class Foo
{
private int _bar;
public int Bar {
get => _bar;
set => _bar = value;
}
}
class Foo
{
private int _bar;
public int Bar {
get => _bar;
set => _bar = value;
}
}
can be shortened to
class Foo
{
public int Bar { get; set; }
}
class Foo
{
public int Bar { get; set; }
}
Dread
DreadOPā€¢7mo ago
would it have made my code shorter?
Angius
Angiusā€¢7mo ago
Does the below look shorter than the above?
No description
Dread
DreadOPā€¢7mo ago
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
Angius
Angiusā€¢7mo ago
Would have made your electronics shorter
Dread
DreadOPā€¢7mo ago
okay so updatecsv is supposed to save it to my file, did i do something wrong there?
Angius
Angiusā€¢7mo ago
No, everything seems fine there
Dread
DreadOPā€¢7mo ago
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?
Angius
Angiusā€¢7mo ago
Just keep it relative That's always the easiest
Buddy
Buddyā€¢7mo ago
Relative for sure!
Dread
DreadOPā€¢7mo ago
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.
Pobiega
Pobiegaā€¢7mo ago
Wdym with a search engine?
Dread
DreadOPā€¢7mo ago
^ 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
Pobiega
Pobiegaā€¢7mo ago
All it says is "should be able to search for an item" That's quite different from making a search engine
Dread
DreadOPā€¢7mo ago
is that not technically a search engine type of thing?
Pobiega
Pobiegaā€¢7mo ago
That's like calling a stick figure a magnificent work of art :p
Dread
DreadOPā€¢7mo ago
welp šŸ« 
Pobiega
Pobiegaā€¢7mo ago
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?
Dread
DreadOPā€¢7mo ago
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
Pobiega
Pobiegaā€¢7mo ago
If you only allow searching by name and returning the first item that matches the search, then it's literally 1 line of code
Dread
DreadOPā€¢7mo ago
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
Pobiega
Pobiegaā€¢7mo ago
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
Dread
DreadOPā€¢7mo ago
ok ok 1 sec
Pobiega
Pobiegaā€¢7mo ago
But since your product has 3 properties you might want to search in (name, brand, model)...
Dread
DreadOPā€¢7mo ago
let me update that link and send a new one to see what i need to finish other than the search thingy
Pobiega
Pobiegaā€¢7mo ago
I'm on my morning commute so reading large swathes of code rn will be difficult
Dread
DreadOPā€¢7mo ago
BlazeBin - jppsdnhdrzsd
A tool for sharing your source code with the world!
Dread
DreadOPā€¢7mo ago
its okay, one of the other guys might be able to help too
Pobiega
Pobiegaā€¢7mo ago
Can't you go over your own code and compare it with the requirements? That seems like the easiest solution
Dread
DreadOPā€¢7mo ago
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
Pobiega
Pobiegaā€¢7mo ago
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
Dread
DreadOPā€¢7mo ago
i have no clue. i thought adding an item would already by default list the item.
Pobiega
Pobiegaā€¢7mo ago
It returns zero or more items from that collection that match the given predicate
Dread
DreadOPā€¢7mo ago
and i thought the UpdateCSV would just collect the data because thats its job
Pobiega
Pobiegaā€¢7mo ago
"collect the data"?
Dread
DreadOPā€¢7mo ago
but it was eitherthe file path or something else, because the program runs, but does not save to file like save
Pobiega
Pobiegaā€¢7mo ago
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
Dread
DreadOPā€¢7mo ago
like look in my file explorer for it?
Pobiega
Pobiegaā€¢7mo ago
Sure Seems like a good way to verify that it works
Dread
DreadOPā€¢7mo ago
do not have a project/bin/net8.0/debug/
Pobiega
Pobiegaā€¢7mo ago
What's in your project root then?
Dread
DreadOPā€¢7mo ago
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**
Pobiega
Pobiegaā€¢7mo ago
Bin is entirely empty? How are you running your program?
Dread
DreadOPā€¢7mo ago
bin>debug> okay the net8.0 is there now wtf
Dread
DreadOPā€¢7mo ago
itā€™s there now
No description
Pobiega
Pobiegaā€¢7mo ago
start your program once and just to be sure, you're 100% sure you are in the right project directory now right?
Dread
DreadOPā€¢7mo ago
yes 100%
Dread
DreadOPā€¢7mo ago
No description
Pobiega
Pobiegaā€¢7mo ago
okay, now while the program is running, look in that folder again
Dread
DreadOPā€¢7mo ago
net8.0 is still empty
Pobiega
Pobiegaā€¢7mo ago
not possible 1 sec
Dread
DreadOPā€¢7mo ago
right?
No description
Dread
DreadOPā€¢7mo ago
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
Pobiega
Pobiegaā€¢7mo ago
add this to the top of your Main Console.WriteLine(Directory.GetCurrentDirectory()); you have not actually shown any paths so I cant tell
Dread
DreadOPā€¢7mo ago
hey 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
Pobiega
Pobiegaā€¢7mo ago
O_O
Dread
DreadOPā€¢7mo ago
itā€™s for schooling
Pobiega
Pobiegaā€¢7mo ago
onedrive as source control... by probably syncing the entire repos folder including build artifacts jfc thats nightmare fuel
Dread
DreadOPā€¢7mo ago
i do have a whole folder of repos lol
Pobiega
Pobiegaā€¢7mo ago
thats fine but not using git and .gitignore files to manage it is not fine šŸ˜„ anyways
Dread
DreadOPā€¢7mo ago
well i have no say here
Pobiega
Pobiegaā€¢7mo ago
if you open that folder up, now can you see your csv file?
Dread
DreadOPā€¢7mo ago
iā€™m just a student šŸ˜‚ yes i can Electronics.csv
Pobiega
Pobiegaā€¢7mo ago
good ok so only the search left then
Dread
DreadOPā€¢7mo ago
okay so my ReadData is supposed to realistically load my data from the csv right?
Pobiega
Pobiegaā€¢7mo ago
yes?
Dread
DreadOPā€¢7mo ago
okay yeah iā€™ll do that search engine and comeback real quick and let you know if itā€™s finally fully functional.
Pobiega
Pobiegaā€¢7mo ago
okidoki I go eat breakfast šŸ™‚
Dread
DreadOPā€¢7mo ago
when i tell you ive been working on this project for 5 hours.. lol enjoy
Pobiega
Pobiegaā€¢7mo ago
thats absolutely fine, we all gotta start somewhere
Dread
DreadOPā€¢7mo ago
Dread
DreadOPā€¢7mo ago
oh wait private static Electronics? SearchEngine(string? name) { return electronicsList.FirstOrDefault(p => p.name.Equals(name, StringComparison.OrdinalIgnoreCase)); } does that look right at all
Pobiega
Pobiegaā€¢7mo ago
yes but also no šŸ™‚
Dread
DreadOPā€¢7mo ago
fuck
Pobiega
Pobiegaā€¢7mo ago
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
Dread
DreadOPā€¢7mo ago
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
Pobiega
Pobiegaā€¢7mo ago
on search in particular or overall?
Dread
DreadOPā€¢7mo ago
search
Pobiega
Pobiegaā€¢7mo ago
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
Dread
DreadOPā€¢7mo ago
is there a better way you wouldā€™ve did the method as opposed to what i did?
Pobiega
Pobiegaā€¢7mo ago
well, I'd fix the three issues I listed above with something like this:
private static IEnumerable<Product> Search(string query)
{
return list.Where(x
=> x.Name.Contains(query, StringComparison.InvariantCultureIgnoreCase)
|| x.Brand.Contains(query, StringComparison.InvariantCultureIgnoreCase)
|| x.Model.Contains(query, StringComparison.InvariantCultureIgnoreCase));
}
private static IEnumerable<Product> Search(string query)
{
return list.Where(x
=> x.Name.Contains(query, StringComparison.InvariantCultureIgnoreCase)
|| x.Brand.Contains(query, StringComparison.InvariantCultureIgnoreCase)
|| x.Model.Contains(query, StringComparison.InvariantCultureIgnoreCase));
}
Dread
DreadOPā€¢7mo ago
yeah i have never wrote nothing like that lol only the stringcomparison
Pobiega
Pobiegaā€¢7mo ago
now it returns zero or more, doesnt require exact name, and searches on all three properties
Dread
DreadOPā€¢7mo ago
whatā€™s with the x.
Pobiega
Pobiegaā€¢7mo ago
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
Dread
DreadOPā€¢7mo ago
whew my brain is not braining
Pobiega
Pobiegaā€¢7mo ago
does it help if we give it a longer name?
private static IEnumerable<Product> Search(string query)
{
return list.Where(product
=> product.Name.Contains(query, StringComparison.InvariantCultureIgnoreCase)
|| product.Brand.Contains(query, StringComparison.InvariantCultureIgnoreCase)
|| product.Model.Contains(query, StringComparison.InvariantCultureIgnoreCase));
}
private static IEnumerable<Product> Search(string query)
{
return list.Where(product
=> product.Name.Contains(query, StringComparison.InvariantCultureIgnoreCase)
|| product.Brand.Contains(query, StringComparison.InvariantCultureIgnoreCase)
|| product.Model.Contains(query, StringComparison.InvariantCultureIgnoreCase));
}
Dread
DreadOPā€¢7mo ago
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
Pobiega
Pobiegaā€¢7mo ago
huh can you show the errors?
Dread
DreadOPā€¢7mo ago
No description
Dread
DreadOPā€¢7mo ago
No description
Dread
DreadOPā€¢7mo ago
attempt #2
Pobiega
Pobiegaā€¢7mo ago
You are calling the method without passing in the search parameter (query) Also, $screenshot
MODiX
MODiXā€¢7mo ago
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.
Dread
DreadOPā€¢7mo ago
oh sorry
Dread
DreadOPā€¢7mo ago
No description
SG97
SG97ā€¢7mo ago
don't modify code while running and you have 2 implementations of SearchEngine() it seems
Dread
DreadOPā€¢7mo ago
it suggested that i made add that throw exception in there
SG97
SG97ā€¢7mo ago
sure this logic needs to go there then
Pobiega
Pobiegaā€¢7mo ago
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
Dread
DreadOPā€¢7mo ago
thats originally what it was essentially okay so case 3: (Method) break; and redo the method?
Pobiega
Pobiegaā€¢7mo ago
Method(); And fix up your method so it handles both input and output
Dread
DreadOPā€¢7mo ago
yeah thatā€™s what i meant lol just exhausted
Dread
DreadOPā€¢7mo ago
No description
Pobiega
Pobiegaā€¢7mo ago
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 in
Dread
DreadOPā€¢7mo ago
do i add a field for query? because thatā€™s the only error right now
Pobiega
Pobiegaā€¢7mo ago
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
Dread
DreadOPā€¢7mo ago
iā€™ve just been up about 18 hours and have to be up in 6
Angius
Angiusā€¢7mo ago
Go to sleep
Dread
DreadOPā€¢7mo ago
iā€™m going to bed now
Pobiega
Pobiegaā€¢7mo ago
sleep well
Dread
DreadOPā€¢7mo ago
thank you guys for the help.
Want results from more Discord servers?
Add your server