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
57 Replies
$helloworld to get your basics covered
$projects to make some stuff, practice makes perfect and what not
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
yep, I'm currently learning it, I think I'm in the part 3
Besides that, solving the Advent of Code tasks with C# can be fun and challenging
noted, thanks !
exercism is pretty good too, but nothing beats Advent of Code
https://adventofcode.com/
This is the official website ?
ye
alright, thanks guys, really appreciate
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
yeah I see
2sec, will just try to log in
Seems to be what the competition is about
So AoC would be perfect
These are the questions ?
well the first one ?
ye
ok ok noted, ty !
tip: this is good to learn unit testing
unit testing is when we test specific part of our code? like testing particular functions ?
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"
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
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 findyeah 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
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
here DataRow makes more sense
hmm but DataRow refers to what ?
The incoming function ?
like ExplodeTest or SplitTest?
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 thatah ok I see
i think xunit call it Theory for multiple rows, and Fact for regular
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
here for e.g, the DataRow is tested for each 2 functions? like each 2 functions will receive x DataRow ?
ExplodeTest will be called 5 times, with the rows above it
Think of it this way:
and SplitTest 3 times?
correct
yeah I see
last question
what about the triple double quotes pls
why are they used or for what are they used
Raw string literal - C# feature specifications
This feature describes raw string literals. Raw string literals enable string literals to avoid almost all escape sequences.
Triple-quotes let you write "raw" strings
large strings where newlines etc are imbeded
They also strip the indentation to the closing quotes indent
wait will just read 2sec
it's used basically to keep the syntax of what we want without using escape sequences ?
Yeah
And without having to do weird indentation
Like, instead of
you can do
to keep the indent levels nice and consistent
super nice for being able to just paste in a snippet from somewhere
and not having to edit it
Yeah, amazing for literal JSON strings
Or CSS, or HTML, or SQL, or anything really
AoC sample inputs and json are my two primary usages 😄
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 ?
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 😛yeah true
I understand it though, thanks !!
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?
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!
If I writing everything myself, how could I verify the answer I got is right? And I have done it in an optimal way?
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
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..
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
Thanks a lot.. solved exercism problems and found it pretty good (especially the mentorship part)..