C
C#•2d ago
Faker

Resource to practice C#

Hello guys, sorry to disturb you all; my university will shortly organise a competition in C# where we would have to solve a series of challenges. I just started to learn C#. I'm not new to programming (I'm still a beginner though) but I'm a beginner to C#. Does anyone knows any website where I can practice pls, from basic questions to data structure etc pls
No description
57 Replies
Angius
Angius•2d ago
$helloworld to get your basics covered
Angius
Angius•2d ago
$projects to make some stuff, practice makes perfect and what not
MODiX
MODiX•2d ago
Collections of application ideas that anyone can solve in any programming language to improve coding skills: https://github.com/dotnet/dotnet-console-games https://github.com/karan/Projects https://github.com/florinpop17/app-ideas
Faker
FakerOP•2d ago
yep, I'm currently learning it, I think I'm in the part 3
Angius
Angius•2d ago
Besides that, solving the Advent of Code tasks with C# can be fun and challenging
Faker
FakerOP•2d ago
noted, thanks !
Pobiega
Pobiega•2d ago
exercism is pretty good too, but nothing beats Advent of Code
Faker
FakerOP•2d ago
https://adventofcode.com/ This is the official website ?
Angius
Angius•2d ago
ye
Faker
FakerOP•2d ago
alright, thanks guys, really appreciate
Pobiega
Pobiega•2d ago
AoC is literally just a collection of increasingly difficult programming puzzles, nothing C# specific. It is however fantastic material to use for practice, and it will test your language knowledge quite well. What it does not let you train is the "standard" libraries around .NET, like ASP.NET, WPF etc. Its purely a "calculate the output based on the input" type thing, so you wont be making any web apis etc
Faker
FakerOP•2d ago
yeah I see 2sec, will just try to log in
Angius
Angius•2d ago
Seems to be what the competition is about So AoC would be perfect
Faker
FakerOP•2d ago
These are the questions ?
No description
Faker
FakerOP•2d ago
well the first one ?
Angius
Angius•2d ago
ye
Faker
FakerOP•2d ago
ok ok noted, ty !
Sehra
Sehra•2d ago
tip: this is good to learn unit testing
Faker
FakerOP•2d ago
unit testing is when we test specific part of our code? like testing particular functions ?
Pobiega
Pobiega•2d ago
Yep, very true. Each puzzle has one or more "samples" that you can use to make a unit test for your solution yeah, but one of those functions is "Solve day 1 part 1"
Sehra
Sehra•2d ago
No description
Faker
FakerOP•2d ago
hmm you mean we test each particular function when needed, like for part 1? sorrryy, I'm still a beginner, I've not yet too technical :c
Pobiega
Pobiega•2d ago
look at Sehras screenshot they wrote a unittest that tests the Day1.Part1() function with the sample input, expecting a result of 11 this lets you verify when your solution appears to be correct ie, you run your test cases and tweak your code until they pass. then you try the real input and go from there. If that doesnt work, you start debugging, sometimes setting up MORE unit tests for particular scenarios you find
Faker
FakerOP•2d ago
yeah I see how does the DataRow syntax work ? I mean how does it call the required function ? Also, would really appreciate if someone can explain why we use the tripple quotes pls what's special about it
Sehra
Sehra•2d ago
it's just a template i use, don't really need DataRow here since it's one test. but it takes the parameters and call the method once for each row
Sehra
Sehra•2d ago
here DataRow makes more sense
No description
Faker
FakerOP•2d ago
hmm but DataRow refers to what ? The incoming function ? like ExplodeTest or SplitTest?
Angius
Angius•2d ago
The test goes through all data rows First string in it foes to expected, second goes into input That way you can test for multiple inputs and outputs with a single test Do note: different testing frameworks might have different syntax for that
Faker
FakerOP•2d ago
ah ok I see
Sehra
Sehra•2d ago
i think xunit call it Theory for multiple rows, and Fact for regular
Pobiega
Pobiega•2d ago
yes Also, don't get too fixated on the names of the attributes etc - Sehra uses MsTest which is the least used test framework in .NET currently so its different from Xunit, or NUnit
Faker
FakerOP•2d ago
here for e.g, the DataRow is tested for each 2 functions? like each 2 functions will receive x DataRow ?
Sehra
Sehra•2d ago
ExplodeTest will be called 5 times, with the rows above it
Angius
Angius•2d ago
Think of it this way:
foreach (row in datatarows)
run test(row[0], row[1])
foreach (row in datatarows)
run test(row[0], row[1])
Faker
FakerOP•2d ago
and SplitTest 3 times?
Sehra
Sehra•2d ago
correct
Faker
FakerOP•2d ago
yeah I see last question what about the triple double quotes pls why are they used or for what are they used
Sehra
Sehra•2d ago
Raw string literal - C# feature specifications
This feature describes raw string literals. Raw string literals enable string literals to avoid almost all escape sequences.
Angius
Angius•2d ago
Triple-quotes let you write "raw" strings
Pobiega
Pobiega•2d ago
large strings where newlines etc are imbeded
Angius
Angius•2d ago
They also strip the indentation to the closing quotes indent
Faker
FakerOP•2d ago
wait will just read 2sec it's used basically to keep the syntax of what we want without using escape sequences ?
Angius
Angius•2d ago
Yeah And without having to do weird indentation Like, instead of
void Foo()
{
var s = @"
Hello
World
";
}
void Foo()
{
var s = @"
Hello
World
";
}
you can do
void Foo()
{
var s = """
Hello
World
""";
}
void Foo()
{
var s = """
Hello
World
""";
}
to keep the indent levels nice and consistent
Pobiega
Pobiega•2d ago
super nice for being able to just paste in a snippet from somewhere and not having to edit it
Angius
Angius•2d ago
Yeah, amazing for literal JSON strings Or CSS, or HTML, or SQL, or anything really
Pobiega
Pobiega•2d ago
AoC sample inputs and json are my two primary usages 😄
Faker
FakerOP•2d ago
oh ok I see the @ symbol, I think it's known as the verbatim, doesn't preserve the format, just it allows us not to use escape sequences ?
Pobiega
Pobiega•2d ago
yeah it doesnt handle indentations etc raw strings also handle stuff like { really well you can even do interpolated raw strings with { in it, like json you wont need to practice raw strings for your C# competition thou 😛
Faker
FakerOP•2d ago
yeah true I understand it though, thanks !!
Rizwan Riaz
Rizwan Riaz•2d ago
I have also signed up on AoC, read the first question, got the input.. But there is no integrated environment like LeetCode or Hackerrank where I could write code? like specific input params, test cases etc?
Pobiega
Pobiega•2d ago
No, its intentionally tool/language agnostic Your input for each day is always a textfile, and your answer is either a number or a short string Some people solve it using Excel!
Rizwan Riaz
Rizwan Riaz•2d ago
If I writing everything myself, how could I verify the answer I got is right? And I have done it in an optimal way?
Pobiega
Pobiega•2d ago
You submit the answer on the webpage. If you got it right, it tells you. Regarding "optimal way" there is no such thing Do you optimize for lowest memory usage? Execution time? Development time? Maintainability/ease of understanding? Too many variables
Rizwan Riaz
Rizwan Riaz•2d ago
Oh, I am having issues in logic building and not writing code that is maintainable and efficient.. So AoC would help me in logic building but not the others then..
Pobiega
Pobiega•23h ago
it will help in the same way that writing code in general helps, but it wont hold your hand or guide you in any way towards that goal, no its literally just a bunch of puzzles it doesnt even tell you what algo to use, or even what family of algo its not really aimed at beginners, but the first few days are usually very easy so even someone with very basic understanding can do themn if you want to specifically practice writing readable and maintainable code, I recommend https://exercism.org/ its a bit like leetcode but you can have your code reviewed by a mentor
Rizwan Riaz
Rizwan Riaz•2h ago
Thanks a lot.. solved exercism problems and found it pretty good (especially the mentorship part)..

Did you find this page helpful?