Giter Club home page Giter Club logo

dotnetkoans's Introduction

.NET Koans

Build & Test All Contributors

The .NET Koans walk you along the path to enlightenment in order to learn C# on .NET. The goal is to learn C# syntax, structure and some common functions and libraries available on the .NET platform. .NET is a cross platform environment that runs happily on Windows, OS X and Linux. It is super simple to get started learning.

The Structure

The koans are broken out into areas by file, arrays are covered in AboutArrays.cs, lambdas are introduced in AboutLambdas.cs, etc. They are presented in order in the PathToEnlightenment.cs file.

Each koan builds up your knowledge of C# and builds upon itself. It will stop at the first place you need to correct.

Some koans simply need to have the correct answer substituted for an incorrect one. Some, however, require you to supply your own answer. If you see the object FILL_ME_IN listed, it is a hint to you to supply your own code in order to make it work correctly.

Getting Started

Running Locally

  1. Install .NET SDK 6.0.
  2. Install Visual Studio Code, the Insiders Edition is highly recommended.
  3. Clone the repository: git clone https://github.com/NotMyself/DotNetKoans.git.
  4. Change directory into the cloned repository cd DotNetKoans.
  5. Restore packages: dotnet restore.
  6. Open the project in VSCode code-insiders . or code . depending on what version you chose to install.
  7. Run the koans in watch mode: dotnet watch --quiet run.
    • Note: The --quiet flag is used here to suppress messages from the watch framework.
  8. Follow along with the instructions printed to your console. Each time you save a *.cs file, the project will be built and run again for you automatically.

Contributing

Want to contribute? Check out our Code of Conduct and Contributing docs. This project follows the all-contributors specification. Contributions of any kind welcome!

There are many topics yet to be covered by this set of koans. I have added a handful of needed topics as issues and tagged them as Up for Grabs. There are even some specifically tagged as Beginner Friendly.

If you have never contributed to an open source project, let those be your first. I promise to work with you to get your contribution into the repository and be friendly and encouraging about it. It is what Jim would have done.

If you think a topic is missing, propose it's inclusion by submitting an issue yourself. Or better yet submit the issue and an accompanying pull request with how you think the topic should be introduced. Think about beginners in your effort; be clear and informative, be concise and most of all be playful with your examples.

About Koans

This project is based on the work of Cory Foy and his original multi-language project DotNetKoans. If you are interested in learning VB.NET, please look at his fine work.

Programming Koans came about because of the most enlightened Ruby Koans by Jim Weirich. Jim was a great teacher & programmer whom I had the pleasure of meeting, learning from and playing games with. Rest in peace, sir. We will continue your effort to bring a love of the craft to anyone willing to learn.

For a fuller explanation of what is going here, see the blog post Learn C# on Windows, OSX or Linux with the .NET Koans

Contributors ✨

Thanks goes to these wonderful people (emoji key):

John Hoerr
John Hoerr

πŸ’»
Victor Grigoriu
Victor Grigoriu

πŸ’»
James Naylor
James Naylor

πŸ’»
Samuel Cherinet
Samuel Cherinet

πŸ’»
Chris
Chris

πŸ’»
Delaine Wendling
Delaine Wendling

πŸ’»
Allen
Allen

πŸ’»
Jonathan Couldridge
Jonathan Couldridge

πŸ’»
Lukas Sinkus
Lukas Sinkus

πŸ’»
Richard D
Richard D

πŸ’»
Stratos Kourtzanidis
Stratos Kourtzanidis

πŸ’»
Agustin
Agustin

πŸ’»
Matthew Parsons
Matthew Parsons

πŸ’»
Jamie MacLeod
Jamie MacLeod

πŸ’»
Stuart Harrison
Stuart Harrison

πŸ’»
Chris Jones
Chris Jones

πŸ“–
Atanas Pashkov
Atanas Pashkov

πŸ’»
Tomasz Cielecki
Tomasz Cielecki

πŸ’»
SophieLemos
SophieLemos

πŸ’» πŸ› 🎨 πŸ“– πŸ€”
Dan Schnau
Dan Schnau

πŸ› πŸ“–
Joshua Belden
Joshua Belden

πŸ’»
Shawn Vause
Shawn Vause

πŸ’»
Jeannie Nguyen
Jeannie Nguyen

🎨
Adam
Adam

πŸ’»
Ferrier Benjamin
Ferrier Benjamin

πŸ’¬ πŸ’»
Ibrahim Islam
Ibrahim Islam

πŸ’»
Nikiforov Alexey
Nikiforov Alexey

πŸ’»
Ozge Cimendere
Ozge Cimendere

πŸ’»
Jakub Rusek
Jakub Rusek

πŸ’»
RAFAELDEV2016
RAFAELDEV2016

🎨
Cedric Rup
Cedric Rup

πŸ’»
Sophie Obomighie
Sophie Obomighie

πŸ‘€
Scott Milliorn
Scott Milliorn

πŸ“–
Thomas M. SchΓΆller
Thomas M. SchΓΆller

πŸ’»
coder2213
coder2213

πŸ’»
Leila
Leila

πŸ’»
Marcin Kolenda
Marcin Kolenda

🚧
Keith Gonzalez
Keith Gonzalez

πŸ’»
farbodsr
farbodsr

πŸ’»

This project follows the all-contributors specification. Contributions of any kind welcome!

dotnetkoans's People

Contributors

allcontributors[bot] avatar allenz0810 avatar beforan avatar benjioe avatar cedricrup avatar cestrand avatar cheesebaron avatar cmdkeen avatar dutts avatar euronay avatar farbodsr avatar jeannienguyen avatar jhoerr avatar kgonzalezasc avatar leilazarban avatar lus1n avatar maxatoms avatar melkor54248 avatar nauhcnoohc avatar nikiforovall avatar notmyself avatar ocimen avatar orangutech avatar pezholio avatar ptvbnk avatar rafaeldev2016 avatar samyou-softwire avatar technicallyharwell avatar tomizechsterson avatar vgrigoriu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dotnetkoans's Issues

Can't Build, error SC0021

Product Information:
Version: 2.1.4
Runtime Environment:
OS Name: Mac OS X
OS Version: 10.13
OS Platform: Darwin
RID: osx.10.12-x64
Base Path: /usr/local/share/dotnet/sdk/2.1.4/

Microsoft .NET Core Shared Framework Host

Version : 2.0.5
Build : 17373eb129b3b05aa18ece963f8795d65ef8ea54

CompHostNameHere:DotNetCoreKoans notu$ dotnet watch --quiet run Koans/AboutLinq.cs(41,38): error CS0021: Cannot apply indexing with [] to an expression of type 'IEnumerable<int>' [/Users/notu/code/DotNetCoreKoans/DotNetCoreKoans.csproj] Koans/AboutArrays.cs(41,13): warning xUnit2015: Do not use typeof() expression to check the exception type. [/Users/notu/code/DotNetCoreKoans/DotNetCoreKoans.csproj] Koans/AboutDelegates.cs(135,4): warning xUnit2013: Do not use Assert.Equal() to check for collection size. [/Users/notu/code/DotNetCoreKoans/DotNetCoreKoans.csproj] Koans/AboutFloats.cs(59,13): warning xUnit2015: Do not use typeof() expression to check the exception type. [/Users/notu/code/DotNetCoreKoans/DotNetCoreKoans.csproj] Koans/AboutNull.cs(24,13): warning xUnit2015: Do not use typeof() expression to check the exception type. [/Users/notu/code/DotNetCoreKoans/DotNetCoreKoans.csproj] Koans/AboutGenericContainers.cs(131,4): warning xUnit2015: Do not use typeof() expression to check the exception type. [/Users/notu/code/DotNetCoreKoans/DotNetCoreKoans.csproj] Koans/AboutGenericContainers.cs(219,4): warning xUnit2015: Do not use typeof() expression to check the exception type. [/Users/notu/code/DotNetCoreKoans/DotNetCoreKoans.csproj]

Line 41 is ` Assert.Equal(FILL_ME_IN, lowNums[0]);

Could not load file or assembly Microsoft.DotNet.ProjectModel

When trying to run this on Windows 10, it crashes. (And yes, I've installed, re-installed and re-re-installed .NET Core 1.0)

Console output:

C:\Dev\Git\DotNetCoreKoans>dotnet restore
log  : Restoring packages for C:\Dev\Git\DotNetCoreKoans\project.json...
log  : Restoring packages for tool 'Microsoft.DotNet.Watcher.Tools' in C:\Dev\Git\DotNetCoreKoans\project.json...
log  : Lock file has not changed. Skipping lock file write. Path: C:\Dev\Git\DotNetCoreKoans\project.lock.json
log  : C:\Dev\Git\DotNetCoreKoans\project.json
log  : Restore completed in 2079ms.

C:\Dev\Git\DotNetCoreKoans>dotnet watch run
Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.DotNet.ProjectModel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
   at Microsoft.DotNet.Watcher.Tools.Program.<>c__DisplayClass3_0.<MainInternal>b__0()
   at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
   at Microsoft.DotNet.Watcher.Tools.Program.MainInternal(String[] args, CancellationToken cancellationToken)
   at Microsoft.DotNet.Watcher.Tools.Program.Main(String[] args)

"error NU1605: Detected package downgrade" for multiple packages

From a clean clone of the repo, building on VS for Mac (7.2) reports the following packages as downgrades.

  • System.Net.Primitives
  • Microsoft.DotNet.Cli.Utils
  • System.Net.Sockets
  • System.Security.Principal

Cleaning Solution: DotNetCoreKoans (Debug)
Build started 16/10/2017 21:49:57.


Project "/Users/richard/Documents/Dev/DotNetCoreKoans/DotNetCoreKoans.csproj" (Clean target(s)):

Target ReportAssetsLogMessages:
/Users/richard/Documents/Dev/DotNetCoreKoans/DotNetCoreKoans.csproj : error NU1605: Detected package downgrade: System.Net.Primitives from 4.3.0 to 4.0.11. Reference the package directly from the project to select a different version.
/Users/richard/Documents/Dev/DotNetCoreKoans/DotNetCoreKoans.csproj : error NU1605: DotNetCoreKoans (>= 2.0.0) -> Microsoft.DotNet.Cli.Utils (>= 2.0.0) -> Microsoft.Build (>= 15.3.409) -> System.IO.Pipes (>= 4.0.0) -> System.Net.Sockets (>= 4.1.0) -> runtime.win.System.Net.Sockets (>= 4.3.0) -> System.Net.Primitives (>= 4.3.0)
/Users/richard/Documents/Dev/DotNetCoreKoans/DotNetCoreKoans.csproj : error NU1605: DotNetCoreKoans (>= 2.0.0) -> Microsoft.DotNet.Cli.Utils (>= 2.0.0) -> Microsoft.Build (>= 15.3.409) -> System.IO.Pipes (>= 4.0.0) -> System.Net.Primitives (>= 4.0.11)
/Users/richard/Documents/Dev/DotNetCoreKoans/DotNetCoreKoans.csproj : error NU1605: Detected package downgrade: System.Security.Principal from 4.3.0 to 4.0.1. Reference the package directly from the project to select a different version.
/Users/richard/Documents/Dev/DotNetCoreKoans/DotNetCoreKoans.csproj : error NU1605: DotNetCoreKoans (>= 2.0.0) -> Microsoft.DotNet.Cli.Utils (>= 2.0.0) -> Microsoft.Build (>= 15.3.409) -> System.IO.Pipes (>= 4.0.0) -> System.Net.Sockets (>= 4.1.0) -> runtime.win.System.Net.Sockets (>= 4.3.0) -> System.Security.Principal.Windows (>= 4.3.0) -> System.Security.Principal (>= 4.3.0)
/Users/richard/Documents/Dev/DotNetCoreKoans/DotNetCoreKoans.csproj : error NU1605: DotNetCoreKoans (>= 2.0.0) -> Microsoft.DotNet.Cli.Utils (>= 2.0.0) -> Microsoft.Build (>= 15.3.409) -> System.IO.Pipes (>= 4.0.0) -> System.Security.Principal (>= 4.0.1)
Build continuing because "ContinueOnError" on the task "ReportAssetsLogMessages" is set to "ErrorAndContinue".
Done building target "ReportAssetsLogMessages" in project "DotNetCoreKoans.csproj" -- FAILED.

Done building project "DotNetCoreKoans.csproj" -- FAILED.

Build FAILED.

/Users/richard/Documents/Dev/DotNetCoreKoans/DotNetCoreKoans.csproj : error NU1605: Detected package downgrade: System.Net.Primitives from 4.3.0 to 4.0.11. Reference the package directly from the project to select a different version.
/Users/richard/Documents/Dev/DotNetCoreKoans/DotNetCoreKoans.csproj : error NU1605: DotNetCoreKoans (>= 2.0.0) -> Microsoft.DotNet.Cli.Utils (>= 2.0.0) -> Microsoft.Build (>= 15.3.409) -> System.IO.Pipes (>= 4.0.0) -> System.Net.Sockets (>= 4.1.0) -> runtime.win.System.Net.Sockets (>= 4.3.0) -> System.Net.Primitives (>= 4.3.0)
/Users/richard/Documents/Dev/DotNetCoreKoans/DotNetCoreKoans.csproj : error NU1605: DotNetCoreKoans (>= 2.0.0) -> Microsoft.DotNet.Cli.Utils (>= 2.0.0) -> Microsoft.Build (>= 15.3.409) -> System.IO.Pipes (>= 4.0.0) -> System.Net.Primitives (>= 4.0.11)
/Users/richard/Documents/Dev/DotNetCoreKoans/DotNetCoreKoans.csproj : error NU1605: Detected package downgrade: System.Security.Principal from 4.3.0 to 4.0.1. Reference the package directly from the project to select a different version.
/Users/richard/Documents/Dev/DotNetCoreKoans/DotNetCoreKoans.csproj : error NU1605: DotNetCoreKoans (>= 2.0.0) -> Microsoft.DotNet.Cli.Utils (>= 2.0.0) -> Microsoft.Build (>= 15.3.409) -> System.IO.Pipes (>= 4.0.0) -> System.Net.Sockets (>= 4.1.0) -> runtime.win.System.Net.Sockets (>= 4.3.0) -> System.Security.Principal.Windows (>= 4.3.0) -> System.Security.Principal (>= 4.3.0)
/Users/richard/Documents/Dev/DotNetCoreKoans/DotNetCoreKoans.csproj : error NU1605: DotNetCoreKoans (>= 2.0.0) -> Microsoft.DotNet.Cli.Utils (>= 2.0.0) -> Microsoft.Build (>= 15.3.409) -> System.IO.Pipes (>= 4.0.0) -> System.Security.Principal (>= 4.0.1)
0 Warning(s)
2 Error(s)

Time Elapsed 00:00:00.31

---------------------- Done ----------------------

Clean: 2 errors, 0 warnings

Warning when running koans

warning : The tool 'microsoft.dotnet.watcher.tools' is now included in the .NET Core SDK. Information on resolving this warning is available at (https://aka.ms/dotnetclitools-in-box)

This appears twice when initiating dotnet watch on the koans and on each file-save, which makes the experience a bit less pleasant. I have a PR (#60) with a fix, and it appears to work:

Remove the ItemGroup/DotNetCliToolReference for microsoft.dotnet.watcher.tools from the csproj file.

This is the link above for your reference, and what I'm basing my changes on

Add Koan AboutDecimals

This koan should be short and to the point.

Things to cover:

  • Range
  • Performance vs. Percision
  • When to use it

error CS0017: Program has more than one entry point defined.

Description

After running dotnet migrate on the existing project, it no longer builds. It appears that vstest injects a second static void Main at build time which causes the build to fail. The current project structure will never compile with the current tools.

Possible Solution

  • Temporarily create a second project and move the test dependencies to it.
  • Completely refactor the application to move tests out of the main project.
  • File bugs and wait for a fix.
  • Shake fist at sky and demand a resolution from god.

This bug is also submitted to xunit/xunit#1172 and microsoft/vstest#636

Steps to reproduce

  1. Clone DotnetCoreKoans
  2. Checkout the vs2017 branch git checkout vs2017
  3. Perform a dotnet restore
  4. Perform a dotnet build

Expected behavior

Console project should successfully build with no errors.

Actual behavior

Engine\Program.cs(8,27,8,31): error CS0017: Program has more than one entry point defined. Compile with /main to specify the type that contains the entry point.

Preload C# Depenencies in the devcontainer

When the project is loaded into codespaces. The output pane becomes active and you can see OmniSharp, .NET Core Debugger and the Razor Language Server being installed.

Note: This is specifically about visual studio code dependencies not the .net project dependencies.

Screen Shot 2020-10-02 at 8 06 18 AM

There should be a way to preload these dependencies.

Update Readme

The project readme suggests that .NET Core SDK 2.1 is required, however the project has already been updated to use .NET Core 3.1, this is just to update the readme to keep it in sync.

Add Contributing Code Tour

To assist new contributors to the codebase, create a code tour for new contributors that walks them through how the application is structured and explains how it works and its goals.

Debugging

In the Visual Studio Code Editor there is no error message displayed to help the user figure out how to solve the Koan.

Semantic Question

So I built this thing and ran it and I'm getting this message in the console:

$ dotnet watch run
[DotNetWatcher] info: Running dotnet with the following arguments: run
[DotNetWatcher] info: dotnet process id: 5428
Project DotNetCoreKoans (.NETCoreApp,Version=v1.0) was previously compiled. Skipping compilation.
AboutAsserts AssertTruth has damaged your karma.
The Master says:
  You have not yet reached enlightenment.
[DotNetWatcher] fail: dotnet exit code: -1
[DotNetWatcher] info: Waiting for a file to change before restarting dotnet...

I did a debug and stepped through the whole thing and it appears as though it's running through several completely empty method blocks and eventually hitting a program exit of -1. So indeed, it was programmed to behave like this. My question is, what exactly is the intended purpose here?

Add Koan AboutLinq

This koan could demostrate basic LINQ functionality.

Things to cover:

  • Where

  • OrderBy

  • Take

  • Any

AboutStrings date time and cultures

Really useful project!

In AboutStrings there's an issue with BuiltInDateFormaters and CustomDateFormaters for those of us outside the USA in that the date format is invalid. Changing to explicitly use the Invariant Culture resolves things.

DateTime.Parse("12/16/2011 2:35:02 PM", CultureInfo.InvariantCulture)

Perhaps a globalization koan might be worth adding ;)

Question about NullIsNotAnObject

What is the relevancy of this koan?

[Step(1)]
public void NullIsNotAnObject()
{
    Assert.True(typeof(object).IsAssignableFrom(null)); //not everything is an object
}

The parameter of IsAssignableFrom is of type Type, and it is documented that it returns false if the parameter is null. So this looks like an implementation detail of this function and not something generally true about objects or null. Am I missing something?

Change ordering of AboutLambdas and AboutDelegates

The AboutLambdas portion of the project is dependent on some knowledge of delegates and even comments "[t]he AboutDelegates Koans introduced you to delegates". However, the program checks for all changes to AboutLambdas before AboutDelegates.

VerbatimStringsCanHandleMultipleLinesToo false negative

Assert in VerbatimStringsCanHandleMultipleLinesToo considers
var literalString = @"I\r\nam a\r\nbroken line";
to be different from verbatimString, throws error:

There was an error, Xunit.Sdk.EqualException: Assert.Equal() Failure                                                           
           Ξ“Γ₯Γ΄ (pos 1)                                                                                                         
Expected: I\r\nam a\r\nbroken line                                                                                             
Actual:   I\r\nam a\r\nbroken line                                                                                             
           Ξ“Γ₯Γ¦ (pos 1)  

Add Koan AboutGlobalization

Strings are tricky beasts. When showing messages to users it appears easy on the surface. But what about your Spanish speaking users? Japanese? This koan should demonstrate how globalization works in .net.

Add Koan About Integers

Add a koan called AboutIntegers that walks a new learner through the intricate details about int and uint.

Line breaks in AboutStrings koan aren't consistent on windows with instructions

Hi,

I'm giving these Koans a go and noticed a discrepancy. I'm running the koans on Windows 10.

My solution to VerbatimStringsCanHandleMultipleLinesToo:

    [Step(6)]
    public void VerbatimStringsCanHandleMultipleLinesToo()
    {
      //Tip: What you create for the literal string will have to 
      //escape the newline characters. For Windows, that would be
      // \r\n. If you are on non-Windows, that would just be \n.
      //We'll show a different way next.
      var verbatimString = @"I
am a
broken line";

      // Make sure to use a literal string.
      // Escaped characters in verbatim strings are covered later.
      var literalString = "I\nam a\nbroken line";
      Assert.Equal(18, verbatimString.Length);
      Assert.Equal(literalString, verbatimString);
    }

In the Tip: bit, it says Windows line breaks are \r\n, and \n otherwise. But I'm running Windows, and I had to just use \n to solve the koan. Not sure if the fix here is to change the Tip: or something else.

Failing Build

Get build in a good state before starting refactoring work.

Add Koan AboutFloats

This koan should be short and to the point.

Things to cover:

  • Range
  • Floating point weirdness
  • When to use it

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.