Note: I recommend reading this gist in order because
Examples 1-6build on each other.
- Example 1: Getting Console Input With
Console.ReadLine
How to get console input.- Example 2: Parsing The Console Input From
StringToInt32
How to convert the console input into a numeric value.- Example 3: Validating Console Input With
Int32.TryParse
How to validate numeric input to prevent bugs in your code.- [Example 4: Looping Until User Provides Valid Input](https://gist.github.com/ZacharyPatten/798ed612
I ran across a practical example of algorithm analysis when I wrote a method that generates unique random values inside a provided range. Figured I would share it...
The code in this article was included in my https://github.com/ZacharyPatten/Towel project. Please check it out if you want to see more code like it. :)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Diagnostics; | |
| using System.Reflection; | |
| using System.Text; | |
| using Towel; | |
| using static Towel.Syntax; | |
| namespace ConsoleCoreSandbox | |
| { | |
| class Program |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using static Towel.Syntax; | |
| namespace Example | |
| { | |
| class Program | |
| { | |
| static void Main() | |
| { | |
| // I made custom Switch syntax. :D |
EDIT: I originally thought this would only work with static (non capturing) expressions, but it should work with captures too, so I crosses out "static".
I think it is possible to allow static expressions and static methods to be used as generic arguments in C#. This would allow for more optimized functional programming without having to wrap functions inside custom struct types. Here is an example:
Details
Overview Code Snippet 1 [click to expand]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Runtime.CompilerServices; | |
| using System.Runtime.Intrinsics; | |
| using System.Runtime.Intrinsics.X86; | |
| using BenchmarkDotNet.Attributes; | |
| using BenchmarkDotNet.Running; | |
| namespace MathSharp.Interactive | |
| { | |
| internal class Program |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Linq.Expressions; | |
| using static Towel.Syntax; | |
| namespace Example | |
| { | |
| class Program | |
| { | |
| static void Main(string[] args) | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| using Towel; | |
| using static Towel.Syntax; | |
| namespace Example | |
| { | |
| class Program | |
| { | |
| static void Main(string[] args) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Reflection; | |
| using static Towel.Syntax; | |
| namespace Example | |
| { | |
| class Program | |
| { | |
| static void Main(string[] args) | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Linq.Expressions; | |
| using System.Numerics; | |
| using static Towel.Syntax; | |
| namespace Example | |
| { | |
| public class Program | |
| { | |
| static void Main(string[] args) |
