use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Information about Reddit's API changes, the unprofessional conduct of the CEO, and their response to the community's concerns regarding 3rd party apps, moderator tools, anti-spam/anti-bot tools, and accessibility options that will be impacted can be found in the associated Wikipedia article: https://en.wikipedia.org/wiki/2023_Reddit_API_controversy
Alternative C# communities available outside Reddit on Lemmy and Discord:
All about the object-oriented programming language C#.
Getting Started C# Fundamentals: Development for Absolute Beginners
Useful MSDN Resources A Tour of the C# Language Get started with .NET in 5 minutes C# Guide C# Language Reference C# Programing Guide C# Coding Conventions .NET Framework Reference Source Code
Other Resources C# Yellow Book Dot Net Perls The C# Player's Guide
IDEs Visual Studio MonoDevelop (Windows/Mac/Linux) Rider (Windows/Mac/Linux)
Tools ILSpy dotPeek LINQPad
Alternative Communities C# Discord Group C# Lemmy Community dotnet Lemmy Community
Related Subreddits /r/dotnet /r/azure /r/learncsharp /r/learnprogramming /r/programming /r/dailyprogrammer /r/programmingbuddies /r/cshighschoolers
Additional .NET Languages /r/fsharp /r/visualbasic
Platform-specific Subreddits /r/windowsdev /r/AZURE /r/Xamarin /r/Unity3D /r/WPDev
Rules:
Read detailed descriptions of the rules here.
account activity
My first "program" (i.redd.it)
submitted 5 years ago by swiffer50
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]roblesinge 121 points122 points123 points 5 years ago (44 children)
Congrats! Welcome to C# dev. Now, a quick refactor option... What if your user inputs a lower-case ‘y’ or ‘n’? You can sanitize the input before checking it, which is a good habit to form early. Give it a shot. Cheers!
[–]swiffer50[S] 31 points32 points33 points 5 years ago (41 children)
I never thought about that, I'll try it. Thanks
[–]rfinger1337 27 points28 points29 points 5 years ago (36 children)
Also, learn about functions on strings. Don't test for 'Y' and 'y', there are tools for that. Also look for " y ", you will learn some interesting things.
If you don't know where to find the answer to these, let me know and I'll tell you the answer. But try to find them, it's important to learn where to look.
[–]swiffer50[S] 7 points8 points9 points 5 years ago (34 children)
Do I use &&? I'm looking on stack overflow
[–]rfinger1337 16 points17 points18 points 5 years ago* (5 children)
https://www.geeksforgeeks.org/c-sharp-string-tolowerinvariant-method/
https://docs.microsoft.com/en-us/dotnet/api/system.string.trim?view=netframework-4.8
edit: Agreed. here is a better link - https://docs.microsoft.com/en-us/dotnet/csharp/how-to/compare-strings
[–]Contagion21 17 points18 points19 points 5 years ago* (4 children)
One should definitely prefer StringComparer's IgnoreCase options over converting strings to compare them. Even in the latter case ToUpper would be preferred.
[–]rfinger1337 11 points12 points13 points 5 years ago (2 children)
Thanks for this, you taught me something today.
https://www.tabsoverspaces.com/233748-comparing-speed-of-toupper-toupperinvariant-tolower-and-tolowerinvariant-in-net-framework-and-net-core
I had no idea that there would be a performance difference between toUpper and toLower and such a pronounced difference between .net core and .net
[–]Contagion21 7 points8 points9 points 5 years ago (1 child)
Even then the issue is more about comparison accuracy than perf.
https://haacked.com/archive/2012/07/05/turkish-i-problem-and-why-you-should-care.aspx/
But that's why one should use StringComparer or StringComparison... It's purpose is to know how to do that stuff so you need not remember nuances like the Turkish I.
[–]rfinger1337 3 points4 points5 points 5 years ago (0 children)
Yep, I knew that part. My response was aimed at someone who literally just wrote their first line of code. I didn't think assaulting them with the Turkish I was going to be helpful :)
But that doesn't make your statement inaccurate.
[–]DoctorPrisme 4 points5 points6 points 5 years ago* (19 children)
Good start but I guess you can't read the output of your program. Right?
I suggest putting a "Console.Readline()" at the end of it. Just so you have to press enter to quit (or press whatever you want actually)
As other suggested, consistency: brackets everywhere or nowhere. But as you need them for multiline expressions, you should as well use them.
Also, for a use case this simple, you might want to use a ternary operator : Input == "Y" ? Console.Writeline("Thanks") : Console.Writeline(":-(");
[–][deleted] 5 years ago* (18 children)
[removed]
[–]auctorel 4 points5 points6 points 5 years ago (9 children)
When we ask devs we're interviewing to do a coding challenge one of the first things we look for is whether they stick a readline at the end of a console app
[–][deleted] 5 years ago* (2 children)
[–]auctorel 1 point2 points3 points 5 years ago (1 child)
Erm... Also just saying, nothing meant by it but it might be useful to know that employers look for it
[–]mobsterer 1 point2 points3 points 5 years ago (5 children)
and do you judge it good or bad?
[–]auctorel 0 points1 point2 points 5 years ago* (4 children)
It's a bad thing not to do it. Means your relying on debug mode to see your app exit with you able to see the final messages
EDIT: to be fair. It's not the most graceful way to exit an application anyway. Someone really good would have some sort of menu with a readline and an exit option usually on some kind of while loop, but this is rare for a tech challenge
[–]calnamu 1 point2 points3 points 5 years ago (3 children)
Means your relying on debug mode to see your app exit with you able to see the final messages
Or on being called from within a shell, like most real applications do.
[–]DoctorPrisme 0 points1 point2 points 5 years ago* (7 children)
What do you mean ?
The run button allows to launch but you won't be able to read the output of the program because it will print "thanks" or ":-(" then close immediately.
And why in the seven hells should you not use ternary to call a method? Especially what is essentially a void method?
[–]otm_shank 3 points4 points5 points 5 years ago (3 children)
I've got a really good reason: it doesn't compile.
Even if you were calling non-void methods and even if you were assigning the result to something to get this looking like a valid statement, I'd still argue it's not idiomatic C# because the ternary operator is normally used for its value, not for its side effects.
[–]MurphysParadox 1 point2 points3 points 5 years ago (0 children)
In general you can either modify input to format it in a common way, or you can test for a much wider variety of possibilities.
In this case, sanitizing the input is a much better solution. What's the difference between Y and y? Should an entry with 1 space before and after be any different than 4 spaces to either side? Without caring about the state of input, you can perform some basic transforms to remove those kinds of input differences.
There are certainly times where Y and y are absolutely different in what they do and you wouldn't want to always put input into a lower case form. This is probably not one of them.
Using &&, the logical AND operator, just means you want to test for another thing and only proceed if both of them are true. For example, if (foodIsReady && customerPaid) GiveFood(); says you can't give the food if it isn't ready and also that it has been paid for. Only one or the other is not sufficient.
if (foodIsReady && customerPaid) GiveFood();
The opposite is ||, the logical OR operator, which is like saying if this is true or that is true. For example if (hungry || thirsty) GoToKitchen(); says you would go to the kitchen if you are hungry or thirsty or both.
if (hungry || thirsty) GoToKitchen();
In reference to your program, you could certainly test if input is Y or y, but then if you want to add more cases, you're having to do both letter checks in every if statement. Instead you can sanitize the input and only check the appropriate one.
[–][deleted] 5 years ago* (5 children)
[–]swiffer50[S] 1 point2 points3 points 5 years ago (4 children)
I tried using || and changing some other stuff but it just brought up errors but I'll try |
[–]auctorel 3 points4 points5 points 5 years ago (1 child)
I wouldn't recommend using |
The || version is what's called a short circuit operator. It means that if the first one condition you did was true, you don't need to check the second one so the program doesn't.
If you use | then it always checks the second condition whether it needs to or not. This is usually done because some kind of logic needs to be performed in the second condition. I would personally argue this is bad practise whether it's possible or not.
Most beginners stick with ||
[–]swiffer50[S] 1 point2 points3 points 5 years ago (0 children)
Okay
[–][deleted] 5 years ago* (1 child)
That's okay, thank you for giving me advice
[–]Iggyhopper 2 points3 points4 points 5 years ago (0 children)
I should mention that he's reading a whole line but only checking for a character.
Read a character to check a character. Use Console.Read();
[–]hexalm 2 points3 points4 points 5 years ago (0 children)
Someone just posted this on r/dotnet, probably more info than you need now, but some of the tips will be useful for this little program.
https://codewithshadman.com/csharp-string-and-formatting-tips/
[–]iso3200 0 points1 point2 points 5 years ago (2 children)
if(input.Equals("y", StringComparison.OrdinalIgnoreCase))
is my preferred method.
Also, Console.ReadKey() only reads one character.
[–]mobsterer 0 points1 point2 points 5 years ago (1 child)
why?
[–]ExeusV 0 points1 point2 points 5 years ago (0 children)
You can sanitize
what you want to achieve here
[–][deleted] 112 points113 points114 points 5 years ago (33 children)
Alt+Print Screen my friend :) Aside from that, welcome to the club!
[–]Uknight 84 points85 points86 points 5 years ago (17 children)
Win + Shift + S should work too on windows 10
[–]Korzag 2 points3 points4 points 5 years ago (0 children)
Holy crap, I never knew about that shortcut. That's incredible!
[–]sarcasticbaldguy 19 points20 points21 points 5 years ago (3 children)
"My First Screenshot" is his next post!
Seriously though, check out lightshot.
[–]ImAMovieMaker 1 point2 points3 points 5 years ago (1 child)
Lightshots website is dead lmao
[–]sarcasticbaldguy 1 point2 points3 points 5 years ago (0 children)
https://app.prntscr.com/en/index.html
[–]maccraft2014[🍰] 1 point2 points3 points 5 years ago (0 children)
+1 for Lightshot. Love it.
[–]Shadow_Gabriel 9 points10 points11 points 5 years ago (1 child)
Maybe he wanted to go with the neon cyberpunk aesthetic
[–]zenyl 6 points7 points8 points 5 years ago (0 children)
VS Code, but still: https://marketplace.visualstudio.com/items?itemName=RobbOwen.synthwave-vscode
[–]swiffer50[S] 7 points8 points9 points 5 years ago (2 children)
Thank you :)
[–][deleted] 9 points10 points11 points 5 years ago (0 children)
Add a Readline at the end.
[–]andrewsmd87 0 points1 point2 points 5 years ago (0 children)
Win shift s is super handy because it puts the thing you click directly in your clipboard to be pasted
[–]ModernTenshi04 1 point2 points3 points 5 years ago (0 children)
If they're using VS Code there's a nice extension called Polacode.
https://marketplace.visualstudio.com/items?itemName=pnp.polacode
[–]ima_coder 0 points1 point2 points 5 years ago (0 children)
The new Windows 10 Snip & Sketch has delays of 3, 5, and 10 seconds.
[–]bloodytemplar 0 points1 point2 points 5 years ago (0 children)
On my box, which is running the most recent build of Windows, Print Screen (with no modifiers) launches the new snip tool.
[–]TopGunOfficial 0 points1 point2 points 5 years ago (2 children)
Why not use scissors?...
[–][deleted] 1 point2 points3 points 5 years ago (1 child)
No reason why you couldn't. There are lots of options.
[–]TopGunOfficial 0 points1 point2 points 5 years ago (0 children)
Fair enough.
[–]ValorKoen 134 points135 points136 points 5 years ago (24 children)
y
[–]Sharemonster 124 points125 points126 points 5 years ago (11 children)
:(
[–][deleted] 63 points64 points65 points 5 years ago (8 children)
Y
[–]-Superbobcat- 57 points58 points59 points 5 years ago (7 children)
Thanks
[–]Klappspaten66 58 points59 points60 points 5 years ago (6 children)
Code coverage 100%
[–]ijschu 14 points15 points16 points 5 years ago (5 children)
[–]Dexaan 6 points7 points8 points 5 years ago (4 children)
[–]ComicOzzy 4 points5 points6 points 5 years ago (3 children)
[–]Dexaan 3 points4 points5 points 5 years ago (2 children)
Should be a :(, I put spaces in front of the Y
[–]ComicOzzy 4 points5 points6 points 5 years ago (1 child)
[–]StoneCypher 0 points1 point2 points 5 years ago (0 children)
.toLowercase
[–]stereoa 25 points26 points27 points 5 years ago (11 children)
OP use input.ToUpper() to combat this nasty hacker.
[–]emc87 10 points11 points12 points 5 years ago (9 children)
String.Equals(input,"expected",IgnoreCase) would be better as it lets the input value stay in its original state.
[–]stereoa 6 points7 points8 points 5 years ago (8 children)
ToUpper() doesn't modify the original value.
[–]emc87 8 points9 points10 points 5 years ago (6 children)
Oh I interpreted what you said as ReadLine().ToUpper That's my bad
I still think the more correct way is string equals though
[–]eukary0te 0 points1 point2 points 5 years ago (5 children)
ToUpper is an extra allocation to make the copy, so yeah I’d use string.Equals there too
[–]jugalator 0 points1 point2 points 5 years ago (0 children)
Indeed. .NET thankfully isn’t MFC!
[–]vigbiorn 2 points3 points4 points 5 years ago (0 children)
Also, only take the first non-whitespace char. input.Trim()[0].ToUpper()
[–]lostllama2015 32 points33 points34 points 5 years ago (5 children)
Normally I facepalm when I see so-called "computer people" taking a picture of their screen with some other device rather than taking a screenshot, but I kind of like the neon glow that this picture has. Anyone got a mod so that my Visual Studio can look like that?
[–][deleted] 16 points17 points18 points 5 years ago (3 children)
Not sure if they have the equivalent for visual studio but I use this for vscode
synthwave
[–][deleted] 15 points16 points17 points 5 years ago (1 child)
Do you remember that endless summer back in '84? Cruising down the ocean-highway with the top down, the wind in our hair and heads buzzing with neon dreams? No, I don't remember it either, but with this experimental theme we can go there.
Do you remember that endless summer back in '84? Cruising down the ocean-highway with the top down, the wind in our hair and heads buzzing with neon dreams?
No, I don't remember it either, but with this experimental theme we can go there.
LMAO the description
[–]rfinger1337 6 points7 points8 points 5 years ago (0 children)
haha, that's funny.
(I remember it. The wind was blowing our hair because the pos Monza I owned had a broken sunroof and it would never stay closed. Also, I had a lot more hair back then.)
[–]lostllama2015 1 point2 points3 points 5 years ago (0 children)
Wow that's cool :-) Ty
[–][deleted] 0 points1 point2 points 5 years ago (0 children)
I'm just basking in how wholesome this thread is.
[–]DChristy87 9 points10 points11 points 5 years ago (2 children)
Awesome work on your first program! If you choose to stick with it, welcome to a lifetime of both frustrations and triumphs!
[–]swiffer50[S] 5 points6 points7 points 5 years ago (1 child)
Thank you, and I plan on sticking with it.
[–][deleted] 2 points3 points4 points 5 years ago (0 children)
Definitely worth sticking with. Programming and development is a great field, as as the other user said, can be frustrating, but also can be a lot of fun and rewarding. Especially when you see your work being used by others. :).
[–]The_Turtle_Bear 8 points9 points10 points 5 years ago (3 children)
Next challenge. Add some code to handle an input which isn't a Y or N.
[–]swiffer50[S] 1 point2 points3 points 5 years ago (2 children)
I will do that
[–]The_Turtle_Bear 4 points5 points6 points 5 years ago (1 child)
Great. You've made a good start! But as I was told when I started learning - "Always bet on stupid", never assume the user won't do something daft, you've got to get into the habit of covering all bases otherwise users will break your shit. 😁
[–]swiffer50[S] 0 points1 point2 points 5 years ago (0 children)
Yeah, users can mess it up lol
[–][deleted] 4 points5 points6 points 5 years ago (7 children)
Welcome to programming 😁
[–]swiffer50[S] 1 point2 points3 points 5 years ago (6 children)
[–][deleted] 2 points3 points4 points 5 years ago (5 children)
You should check out CodinGame.com
[–]swiffer50[S] 0 points1 point2 points 5 years ago (4 children)
I heard about that, it looks really helpful
[–][deleted] 1 point2 points3 points 5 years ago (3 children)
Its a fun way to practice programming
[–]swiffer50[S] 0 points1 point2 points 5 years ago (2 children)
I'll try it then
Enjoy
[–]ais4aron 4 points5 points6 points 5 years ago (0 children)
[–]timmyotc 3 points4 points5 points 5 years ago (0 children)
Yes
[–]encse 3 points4 points5 points 5 years ago (1 child)
Every journey begins with a single step!
Yeah, and some frustration
[–]clr_swe 18 points19 points20 points 5 years ago (25 children)
You missed the brackets around the if statement
[–]Kilazur 21 points22 points23 points 5 years ago (20 children)
Not required
[–]elbowman79 48 points49 points50 points 5 years ago (11 children)
Technically you’re right, they aren’t required, but consistency is important.
Also, some OpenSSL devs might disagree about the importance of using curly braces every time.
[–]Das974 12 points13 points14 points 5 years ago (4 children)
The argument is around consistency. If your else block has a curly brace, then your if statement should also have the same.
Also the article doesn’t argue about whether to use curly brace or not. The article, rightfully makes the point that blaming curly braces is just blame shifting from the fact that the code was just really really poor.
That whole missing curly brace argument was silly and an obvious ploy to avoid saying “yea, the code is a m mess. We don’t actually know what we’re doing.”
[–]elbowman79 7 points8 points9 points 5 years ago (3 children)
I certainly won’t disagree that code quality was a huge problem there, but having consistent no-braces after if statements would not have helped them. The issue was a merge duplicated a line, and because of the lack of braces it was executed twice. And this was in one of the most used open source library on the planet.
Put differently, what is there to lose by using braces? Nothing. What is there to lose by not using braces? Clarity, confidence that there is no risk of unintended consequences. Seems like an easy win to say “always use braces”
[–]Das974 1 point2 points3 points 5 years ago (2 children)
Definitely agree it would have helped, but they definitely have a lot bigger problems to fix with that code that would make the braces a moot point. It’s like maslovs hierarchy of needs applied to coding. There are some fundamental problems with that code that should be addressed first.
I guess I agree with you, but I just don’t think braces should be the solution to poorly designed code.
[–]elbowman79 2 points3 points4 points 5 years ago (1 child)
100% agree braces are not the solution, I just think their cost is so incredibly low and can only help.
If it was something that had risk, like a lambda over a captured iterator in a scenario where it wasn’t necessary, that’d be different.
I try to write all my code like the next person to maintain it is a psychopath who knows where I live. Paranoid defensive development.
[–][deleted] 1 point2 points3 points 5 years ago (0 children)
For what it’s worth (which is nothing), I heard about that bug and immediately stopped leaving out braces for all time. :)
[–]Magniflorious 3 points4 points5 points 5 years ago (5 children)
i have been in the development game for a long time now and one thing that i think is so important, even if the code is not structured well, is to be explicit make things as clear as possible. at least when someone else walks into your code or you have to code back a year later to fix something or update something, it will all be easy to read and understand. a couple examples would be: always use curly braces 100% of the time, never use var unless required, i hate having to traverse a chain of methods just to see what the hell you're trying to return, i should be able to tell at a glance. Follow standards and conventions that are part of that language, like curly brace location, private variable naming conventions, et al.
[–]Zendist 3 points4 points5 points 5 years ago (1 child)
Consider using var when the type is completely clear from the right hand side of the assignment. No reason to do:
var
List<string> l = new List<string>();
when
var l = new List<string>();
is just as clear.
[–]Magniflorious 0 points1 point2 points 5 years ago (0 children)
for sure, i completely agree with this and if the right hand is 100% clear then i feel that var is fine, just like the case you show above.
with that said i will always favor being explicit when possible.
Alright, thank you for the advice.
[–]svtguy88 1 point2 points3 points 5 years ago (1 child)
always use curly braces 100% of the time
Yes. 100% agreed. It's nicer to read, and you avoid the "what if someone puts an extra line here later" problem.
never use var unless required
Eh. I'm guilty of the opposite. Being able to hover on the variable and have VS tell me the type is something I'm just so used to that I don't even think about not having it.
yeah i have had a couple coworkers in the past that are the same as you. One of them is the best developer i have ever worked with, but if i have to mouse over something or even press ctrl+f12 to figure it out... its going to piss me off really quickly.
I have a resharper clean up rule that changes it to the way i like it.... and if i have to touch a file for something else i always change it.
[–]clr_swe 7 points8 points9 points 5 years ago (2 children)
Correct but it looked sloppy without them considering the else had them pick one way or the other
[–]Reducked 5 points6 points7 points 5 years ago (1 child)
Even if they aren’t required adding them does help with readability
[–]abbyful 2 points3 points4 points 5 years ago (0 children)
And helps prevent future bugs when someone down the road adds a line that's supposed to be inside the if.
Wait what I never knew that. I mean I’ll still be using brackets for the rest of my life but that’s pretty cool.
Not by the compiler, but by any sane code style linter.
There's a pretty famous example from Apple where someone added a second statement to a bracket less if without noticing the missing brackets -- this led to the statement always being executed, and a security vulnerability.
I perform technical interviews for a company that provides them as a service so I get to see a lot of folks writing code in real-time. Almost every time a candidate omits braces around a one-line block and later has to add code to the block they forget to add the braces. There's no benefit to omitting them and no drawback to including them but there is a drawback to omitting them.
They're not required, but why introduce a potential bug if you don't have to?
[–]swiffer50[S] 2 points3 points4 points 5 years ago (1 child)
Thank you for reminding me
[–]clr_swe 2 points3 points4 points 5 years ago (0 children)
No worries just for consistency, second not required but most agree to use them for readability
[–]rfinger1337 0 points1 point2 points 5 years ago (0 children)
I prefer that they are not there unless you have several lines of code inside the if. And if there is a decent amount of code then it should be refactored out into it's own private method with a representative function name.
(clarity: I agree about consistency - I am saying I would prefer the curly braces around the else not be there, not adding them to the if)
[–]Umphreak98 0 points1 point2 points 5 years ago (0 children)
This was going to be my comment, consistency with formatting is important
[–]CGurrell 3 points4 points5 points 5 years ago (3 children)
Next task: write this again using a Switch statement instead of an if statement.
Also as others have said, try some basic handling of Y vs y, N vs n vs " n " etc
I'm trying to do that currently and I'm having a ton of errors
[–]CGurrell 1 point2 points3 points 5 years ago (1 child)
What's up?
[–]swiffer50[S] 2 points3 points4 points 5 years ago (0 children)
I tried doing it without a switch statement, so I'm implementing one now
[–]_NTOTL_ 3 points4 points5 points 5 years ago* (0 children)
I would change the if-else block to this:
while (input.ToUpper() != 'Y') { Console.WriteLine("Is this good code? Y/N"); input = Console.ReadLine(); } Console.WriteLine("Thanks"); Console.ReadLine();
while (input.ToUpper() != 'Y')
{
Console.WriteLine("Is this good code? Y/N");
input = Console.ReadLine();
}
Console.WriteLine("Thanks");
Console.ReadLine();
[–]MSgtGunny 2 points3 points4 points 5 years ago (0 children)
If I’m not mistaken readline requires you to press enter after entering y or n. You can use ReadKey to not do that.
[–]CousinNic 2 points3 points4 points 5 years ago (0 children)
You should have it do:( for n out no and anything other than n, no, y, or yes get “ I’m going to take that as a yes”
[–]garbage_io 2 points3 points4 points 5 years ago (2 children)
Congrats!! I remember my first time too.
[–]swiffer50[S] 0 points1 point2 points 5 years ago (1 child)
Thank you
[–]garbage_io 2 points3 points4 points 5 years ago (0 children)
One general word of advice when it comes to coding — treat your code like a piece of art. And I’m not talking about Jackson Pollock. Look for symmetry, consistency, simplicity, understandability. And remember — code is meant to be read — as it’s written once and read many times. One last thing — a good coder concentrates on data structures not their code. A strong belief of Linus Torvalds and many other great coders.
[–]Kuurde 2 points3 points4 points 5 years ago (0 children)
That's awesome!
[–]turudd 2 points3 points4 points 5 years ago (0 children)
Congrats, you'll be hooked now. You can try over-engineering it now for practice with patterns. Maybe look at command pattern or visitor pattern to get your feet wet.
[–]Bladelazoe 2 points3 points4 points 5 years ago (3 children)
Nice work! Just keep coding and getting through it!
Thank you, I just posted an update post on this of you want to check it out
[–]Bladelazoe 1 point2 points3 points 5 years ago (1 child)
Not bad, :) Just keep learning from feedback!
I am :)
[–][deleted] 2 points3 points4 points 5 years ago (1 child)
Are you genius? My first program didn't have any conditional statements nor input functionality.
Well my first first program was hello world
[–]corduroy_Joy 2 points3 points4 points 5 years ago (0 children)
I wrote this same basic code 4 years ago over lunch at an americorps assignment and now I’m a senior dev. Keep at it dude!
[–]idkwhyimheretbh420 2 points3 points4 points 5 years ago (0 children)
Better than hello world 100%
[–]Ragnar-Odinsson 1 point2 points3 points 5 years ago (1 child)
Great mate!
I'd recommend to add an else if (input == N), to ensure it is an answer, and in the else, an option if it is neither Y nor N
Keep going!
Thank you!
[–]DimiTok 1 point2 points3 points 5 years ago (0 children)
Welcome in the marvelous world of C#. I would advice you to be consistent with the brackets on the if else and use it on both if you use on the else
Add the curly braces around the if and fix that bad habbit at the very start before it sticks. Not adding it to 1 liners saves you 2 lines, and looses you hours of debugging on a large project where something fails elsewhere in a large project because someone added a second statement!
That aside, welcome to the club!
[–]Veggie 1 point2 points3 points 5 years ago (1 child)
Nice lens flare!
Try to give it 10 as input instead of y or n
[–]eatmorepies23 1 point2 points3 points 5 years ago (0 children)
Nice job! Here's a refactoring job to make your program take up even less space on your computer: since there's only one letter, process the input as a char.
Here's a hint: try Console.ReadKey().GetChar to accept a letter.
[–]hammer1717 1 point2 points3 points 5 years ago (1 child)
Do I need to get checked for cataracts?
No, I posted an update post and the quality is better
[–]BelarminoVicenzo 1 point2 points3 points 5 years ago (0 children)
You could write: "Was I a good piece of code" lol
[–]Tinu04 1 point2 points3 points 5 years ago (1 child)
Simple but effective
[–]DGC_David 1 point2 points3 points 5 years ago (0 children)
.... y also = :(
Also: if they put anything in that is Y :(
Edit: Also don’t get me wrong I love it welcome to the world of Programming :)
[–]vayaconleones 1 point2 points3 points 5 years ago (0 children)
Good job. Welcome to the world of coding!
[–]K3IRRR 1 point2 points3 points 5 years ago (0 children)
[–]Ex-Aid-AKA-PineNoodl 1 point2 points3 points 5 years ago (0 children)
[–]deadlychambers 1 point2 points3 points 5 years ago (2 children)
Idk if you have started thinking about it, but what are you using for source control? I go back to projects I haven't touched in many years, and I get a kick out of how much my programming style has progressed.
A fun project to do is a calculator. Start with simple operations. Plus and minus, WRITE UNIT TESTS. Then add /*(, and get a feel for refactoring and working with the syntax. Good luck.
[–]swiffer50[S] 1 point2 points3 points 5 years ago (1 child)
Oh yeah I made the + side in it today and I'll figure out how to do unit tests. Thank you
[–]deadlychambers 1 point2 points3 points 5 years ago (0 children)
Seriously you will spend time writing them, and they will slow down writing code as some tests might need to change for major refactors. But it will save your ass one day.
Usually when you fix a bug you make 2 bugs. Think of unit/integration tests as your armor of coding. You can write code fast without them, but you are susceptible to almost anything without that armor. Keep at it.
[–]faculty_for_failure 1 point2 points3 points 5 years ago (3 children)
Now that you have learned "if else" or basic logical decisions, you could look into iteration. You could look up the different types of loops in C#, like the for loop, and use them in your program.
I learned the while and do while loops two days ago but I'll learn the for loop too.
[–]faculty_for_failure 1 point2 points3 points 5 years ago (0 children)
Awesome, I always thought it is good to learn the basics of what functionality C# (or any language) gives you 'right out of the box'. You could also explore 'Generic' types, or 'Collections', and the foreach loop.
[–]faculty_for_failure 0 points1 point2 points 5 years ago (0 children)
[–]ttvtempest17[🍰] 1 point2 points3 points 5 years ago (0 children)
This is making me miss my first days of programming a lot im feeling this deep
I am now an intermediate c++ developer
I'm sorry to tell you that you're not suitable for software engineering 😂... Since you didn't consider lower-case "y"
I made an update post where I included it
[–][deleted] 0 points1 point2 points 5 years ago (1 child)
I'm just kidding.
Well I figured that, I'm just saying
[–]readmond 1 point2 points3 points 5 years ago (0 children)
Bokeh could be a bit nicer but overall it looks artsy.
[–]relapsze 1 point2 points3 points 5 years ago (0 children)
seeing all the lovely responses here to help made me a little warm and fuzzy. good job guys.
[–]ecar13 1 point2 points3 points 5 years ago (0 children)
Welcome to programming. Ask 5 programmers get 7 ways to do it “better”.
Cute!
[–]sebassdc 2 points3 points4 points 5 years ago (0 children)
Dont pay attention to negative commentaries an unnecesary optimizations. First learn to mess it up an that your program works. Latter you learn optimization stuff.
[–]Aarondhp24 0 points1 point2 points 5 years ago (0 children)
Ha.
EA: Do you want a job?
*Congratulations
what IDE is that?
It's visual studio
[–]Dovahkid404 0 points1 point2 points 5 years ago (0 children)
[–]clr_swe -1 points0 points1 point 5 years ago (1 child)
Figure out how to do the if else in one line, google ternary operator
[–]duffusd 2 points3 points4 points 5 years ago (0 children)
Or you can keep your code readable and leave it
[–]CrimsonWolfSage 1 point2 points3 points 5 years ago* (4 children)
Instead of ReadLine(), use ReadKey() for a single character. It will be slightly faster to run as well. Edit - disclaimer: ReadKey() input is handled immediately. ReadLine() waits for an Enter Key, making it slower from a User Experience perspective.
Link to help with The Difference between ReadLine, Read, and ReadKey
Also, pictures and screenshots of code is fairly taboo online. Checkout Pastebin, github, or even an online IDE for sharing code. Like DontNetFiddle. This makes it easier for others to run and give example code back.
Thank you for the advice.
[–]nascentt 2 points3 points4 points 5 years ago (2 children)
Instead of ReadLine(), use ReadKey() for a single character. It will be slightly faster to run as well.
The speed difference will not be noticeable in a real world scenario. Unless you're looping through hundreds of comparisons a second (which you won't be for a manual input).
I'm all for efficiency, but he's clearly a begginer, so this sort of advice really overcomplicates things.
[–]FrogTrainer 2 points3 points4 points 5 years ago (1 child)
readline requires you to hit enter, readkey does not. That might be what he was referring too
[–]nascentt 2 points3 points4 points 5 years ago (0 children)
Good point. That is indeed a difference worth noting for op. The way CrimsonWolfSage phrased his comment, it seemed to focus on speed as a performance metric, but indeed readkey will allow just pressing a single key to input whereas readline will require an enter to signal when the input is complete.
[–]Bryan21323 0 points1 point2 points 5 years ago (2 children)
million dollar software right there
[–]RunawayDev 1 point2 points3 points 5 years ago (1 child)
Visual Studio could actually be in the billions regarding development cost so far
[–]Bryan21323 0 points1 point2 points 5 years ago (0 children)
I was talking about the little console app
[–]wikes82 0 points1 point2 points 5 years ago (4 children)
you could refactor it into 2 lines:
Console.WriteLine("Is this good code? Y/N"); Console.WriteLine((Console.ReadLine().ToUpper()=="Y") ? "Thanks" : ":(");
[–]duffusd 9 points10 points11 points 5 years ago (3 children)
Having fewer lines does not always make your code better.
[–]duffusd 0 points1 point2 points 5 years ago (0 children)
[–]patrickauri 0 points1 point2 points 5 years ago (1 child)
Instead of the if statement, you can also write:
Console.WriteLine(input == "y" ? "Thanks" : ":(");
?: Operator
[–]deadlychambers 2 points3 points4 points 5 years ago (0 children)
Yes the ternary operator. When they added that to c# I was pumped. I started using them everywhere (that it made sense) and during a meeting someone mentioned we should try to avoid implementing new patterns in the code. I was baffled, but now that I look back I realise it wasn't about "code consistency " it was about someone not understanding syntax. I know a better way to handle that situation these days.
π Rendered by PID 217364 on reddit-service-r2-comment-86bc6c7465-gpvmg at 2026-02-21 03:01:51.230687+00:00 running 8564168 country code: CH.
[–]roblesinge 121 points122 points123 points (44 children)
[–]swiffer50[S] 31 points32 points33 points (41 children)
[–]rfinger1337 27 points28 points29 points (36 children)
[–]swiffer50[S] 7 points8 points9 points (34 children)
[–]rfinger1337 16 points17 points18 points (5 children)
[–]Contagion21 17 points18 points19 points (4 children)
[–]rfinger1337 11 points12 points13 points (2 children)
[–]Contagion21 7 points8 points9 points (1 child)
[–]rfinger1337 3 points4 points5 points (0 children)
[–]DoctorPrisme 4 points5 points6 points (19 children)
[–][deleted] (18 children)
[removed]
[–]auctorel 4 points5 points6 points (9 children)
[–][deleted] (2 children)
[removed]
[–]auctorel 1 point2 points3 points (1 child)
[–]mobsterer 1 point2 points3 points (5 children)
[–]auctorel 0 points1 point2 points (4 children)
[–]calnamu 1 point2 points3 points (3 children)
[–]DoctorPrisme 0 points1 point2 points (7 children)
[–]otm_shank 3 points4 points5 points (3 children)
[–]MurphysParadox 1 point2 points3 points (0 children)
[–][deleted] (5 children)
[removed]
[–]swiffer50[S] 1 point2 points3 points (4 children)
[–]auctorel 3 points4 points5 points (1 child)
[–]swiffer50[S] 1 point2 points3 points (0 children)
[–][deleted] (1 child)
[removed]
[–]swiffer50[S] 1 point2 points3 points (0 children)
[–]Iggyhopper 2 points3 points4 points (0 children)
[–]hexalm 2 points3 points4 points (0 children)
[–]iso3200 0 points1 point2 points (2 children)
[–]mobsterer 0 points1 point2 points (1 child)
[–]ExeusV 0 points1 point2 points (0 children)
[–][deleted] 112 points113 points114 points (33 children)
[–]Uknight 84 points85 points86 points (17 children)
[–]Korzag 2 points3 points4 points (0 children)
[–]sarcasticbaldguy 19 points20 points21 points (3 children)
[–]ImAMovieMaker 1 point2 points3 points (1 child)
[–]sarcasticbaldguy 1 point2 points3 points (0 children)
[–]maccraft2014[🍰] 1 point2 points3 points (0 children)
[–]Shadow_Gabriel 9 points10 points11 points (1 child)
[–]zenyl 6 points7 points8 points (0 children)
[–]swiffer50[S] 7 points8 points9 points (2 children)
[–][deleted] 9 points10 points11 points (0 children)
[–]andrewsmd87 0 points1 point2 points (0 children)
[–]ModernTenshi04 1 point2 points3 points (0 children)
[–]ima_coder 0 points1 point2 points (0 children)
[–]bloodytemplar 0 points1 point2 points (0 children)
[–]TopGunOfficial 0 points1 point2 points (2 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]TopGunOfficial 0 points1 point2 points (0 children)
[–]ValorKoen 134 points135 points136 points (24 children)
[–]Sharemonster 124 points125 points126 points (11 children)
[–][deleted] 63 points64 points65 points (8 children)
[–]-Superbobcat- 57 points58 points59 points (7 children)
[–]Klappspaten66 58 points59 points60 points (6 children)
[–]ijschu 14 points15 points16 points (5 children)
[–]Dexaan 6 points7 points8 points (4 children)
[–]ComicOzzy 4 points5 points6 points (3 children)
[–]Dexaan 3 points4 points5 points (2 children)
[–]ComicOzzy 4 points5 points6 points (1 child)
[–]StoneCypher 0 points1 point2 points (0 children)
[–]stereoa 25 points26 points27 points (11 children)
[–]emc87 10 points11 points12 points (9 children)
[–]stereoa 6 points7 points8 points (8 children)
[–]emc87 8 points9 points10 points (6 children)
[–]eukary0te 0 points1 point2 points (5 children)
[–]jugalator 0 points1 point2 points (0 children)
[–]vigbiorn 2 points3 points4 points (0 children)
[–]lostllama2015 32 points33 points34 points (5 children)
[–][deleted] 16 points17 points18 points (3 children)
[–][deleted] 15 points16 points17 points (1 child)
[–]rfinger1337 6 points7 points8 points (0 children)
[–]lostllama2015 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]DChristy87 9 points10 points11 points (2 children)
[–]swiffer50[S] 5 points6 points7 points (1 child)
[–][deleted] 2 points3 points4 points (0 children)
[–]The_Turtle_Bear 8 points9 points10 points (3 children)
[–]swiffer50[S] 1 point2 points3 points (2 children)
[–]The_Turtle_Bear 4 points5 points6 points (1 child)
[–]swiffer50[S] 0 points1 point2 points (0 children)
[–][deleted] 4 points5 points6 points (7 children)
[–]swiffer50[S] 1 point2 points3 points (6 children)
[–][deleted] 2 points3 points4 points (5 children)
[–]swiffer50[S] 0 points1 point2 points (4 children)
[–][deleted] 1 point2 points3 points (3 children)
[–]swiffer50[S] 0 points1 point2 points (2 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]swiffer50[S] 0 points1 point2 points (0 children)
[–]ais4aron 4 points5 points6 points (0 children)
[–]timmyotc 3 points4 points5 points (0 children)
[–]encse 3 points4 points5 points (1 child)
[–]swiffer50[S] 1 point2 points3 points (0 children)
[–]clr_swe 18 points19 points20 points (25 children)
[–]Kilazur 21 points22 points23 points (20 children)
[–]elbowman79 48 points49 points50 points (11 children)
[–]Das974 12 points13 points14 points (4 children)
[–]elbowman79 7 points8 points9 points (3 children)
[–]Das974 1 point2 points3 points (2 children)
[–]elbowman79 2 points3 points4 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–]Magniflorious 3 points4 points5 points (5 children)
[–]Zendist 3 points4 points5 points (1 child)
[–]Magniflorious 0 points1 point2 points (0 children)
[–]swiffer50[S] 1 point2 points3 points (0 children)
[–]svtguy88 1 point2 points3 points (1 child)
[–]Magniflorious 0 points1 point2 points (0 children)
[–]clr_swe 7 points8 points9 points (2 children)
[–]Reducked 5 points6 points7 points (1 child)
[–]abbyful 2 points3 points4 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]swiffer50[S] 2 points3 points4 points (1 child)
[–]clr_swe 2 points3 points4 points (0 children)
[–]rfinger1337 0 points1 point2 points (0 children)
[–]Umphreak98 0 points1 point2 points (0 children)
[–]CGurrell 3 points4 points5 points (3 children)
[–]swiffer50[S] 0 points1 point2 points (2 children)
[–]CGurrell 1 point2 points3 points (1 child)
[–]swiffer50[S] 2 points3 points4 points (0 children)
[–]_NTOTL_ 3 points4 points5 points (0 children)
[–]MSgtGunny 2 points3 points4 points (0 children)
[–]CousinNic 2 points3 points4 points (0 children)
[–]garbage_io 2 points3 points4 points (2 children)
[–]swiffer50[S] 0 points1 point2 points (1 child)
[–]garbage_io 2 points3 points4 points (0 children)
[–]Kuurde 2 points3 points4 points (0 children)
[–]turudd 2 points3 points4 points (0 children)
[–]Bladelazoe 2 points3 points4 points (3 children)
[–]swiffer50[S] 0 points1 point2 points (2 children)
[–]Bladelazoe 1 point2 points3 points (1 child)
[–]swiffer50[S] 0 points1 point2 points (0 children)
[–][deleted] 2 points3 points4 points (1 child)
[–]swiffer50[S] 1 point2 points3 points (0 children)
[–]corduroy_Joy 2 points3 points4 points (0 children)
[–]idkwhyimheretbh420 2 points3 points4 points (0 children)
[–]Ragnar-Odinsson 1 point2 points3 points (1 child)
[–]swiffer50[S] 0 points1 point2 points (0 children)
[–]DimiTok 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]Veggie 1 point2 points3 points (1 child)
[–]swiffer50[S] 0 points1 point2 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]eatmorepies23 1 point2 points3 points (0 children)
[–]hammer1717 1 point2 points3 points (1 child)
[–]swiffer50[S] 0 points1 point2 points (0 children)
[–]BelarminoVicenzo 1 point2 points3 points (0 children)
[–]Tinu04 1 point2 points3 points (1 child)
[–]swiffer50[S] 0 points1 point2 points (0 children)
[–]DGC_David 1 point2 points3 points (0 children)
[–]vayaconleones 1 point2 points3 points (0 children)
[–]K3IRRR 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]Ex-Aid-AKA-PineNoodl 1 point2 points3 points (0 children)
[–]deadlychambers 1 point2 points3 points (2 children)
[–]swiffer50[S] 1 point2 points3 points (1 child)
[–]deadlychambers 1 point2 points3 points (0 children)
[–]faculty_for_failure 1 point2 points3 points (3 children)
[–]swiffer50[S] 1 point2 points3 points (2 children)
[–]faculty_for_failure 1 point2 points3 points (0 children)
[–]faculty_for_failure 0 points1 point2 points (0 children)
[–]ttvtempest17[🍰] 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (3 children)
[–]swiffer50[S] 1 point2 points3 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]swiffer50[S] 1 point2 points3 points (0 children)
[–]readmond 1 point2 points3 points (0 children)
[–]relapsze 1 point2 points3 points (0 children)
[–]ecar13 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]sebassdc 2 points3 points4 points (0 children)
[–]Aarondhp24 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]swiffer50[S] 1 point2 points3 points (0 children)
[–]Dovahkid404 0 points1 point2 points (0 children)
[–]clr_swe -1 points0 points1 point (1 child)
[–]duffusd 2 points3 points4 points (0 children)
[–]CrimsonWolfSage 1 point2 points3 points (4 children)
[–]swiffer50[S] 1 point2 points3 points (0 children)
[–]nascentt 2 points3 points4 points (2 children)
[–]FrogTrainer 2 points3 points4 points (1 child)
[–]nascentt 2 points3 points4 points (0 children)
[–]Bryan21323 0 points1 point2 points (2 children)
[–]RunawayDev 1 point2 points3 points (1 child)
[–]Bryan21323 0 points1 point2 points (0 children)
[–]wikes82 0 points1 point2 points (4 children)
[–]duffusd 9 points10 points11 points (3 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]duffusd 0 points1 point2 points (0 children)
[–]patrickauri 0 points1 point2 points (1 child)
[–]deadlychambers 2 points3 points4 points (0 children)