Skip to content

Instantly share code, notes, and snippets.

View ZacharyPatten's full-sized avatar
👊
It's Morphin' Time

ZacharyPatten

👊
It's Morphin' Time
  • Kansas, United States
  • 19:26 (UTC -05:00)
View GitHub Profile
@ZacharyPatten
ZacharyPatten / ConsoleInput.md
Last active April 18, 2026 01:54
Beginner's Guide To Console Input In C#

Beginner's Guide To Console Input In C#

Note: I recommend reading this gist in order because Examples 1-6 build on each other.

@ZacharyPatten
ZacharyPatten / Unique Random Generation.md
Last active August 2, 2020 01:20
Generating Unique Random Data: A Practical Example Of Algorithm Analysis

Generating Unique Random Data: A Practical Example Of Algorithm Analysis

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. :)

Introduction

@ZacharyPatten
ZacharyPatten / CommandLineArgumentsExamole.cs
Last active December 6, 2019 18:45
A tool that helps you handle command line arguments.
using System;
using System.Diagnostics;
using System.Reflection;
using System.Text;
using Towel;
using static Towel.Syntax;
namespace ConsoleCoreSandbox
{
class Program
@ZacharyPatten
ZacharyPatten / SwitchSyntax.cs
Last active November 21, 2019 11:56
An example of custom Switch syntax in C#. :D
using System;
using static Towel.Syntax;
namespace Example
{
class Program
{
static void Main()
{
// I made custom Switch syntax. :D

Discussion: Static Generic Argument Expressions And Method Constraints

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".

Overview

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]
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
@ZacharyPatten
ZacharyPatten / GenericEnumUnion.cs
Last active October 17, 2019 00:48
An example of a generic enum union type in C#.
using System;
using System.Linq.Expressions;
using static Towel.Syntax;
namespace Example
{
class Program
{
static void Main(string[] args)
{
@ZacharyPatten
ZacharyPatten / DelegatesForIteration.cs
Last active October 6, 2019 13:38
This shows an alternative methodology to System.Collections.Generic.IEnumerable<T> that uses delegates for enumeration rather than an enumerator.
using System;
using System.Collections.Generic;
using Towel;
using static Towel.Syntax;
namespace Example
{
class Program
{
static void Main(string[] args)
@ZacharyPatten
ZacharyPatten / GenericTryParse.cs
Last active October 17, 2019 00:42
Generic TryParse function that works by assuming a static TryParse method exists on the generic type.
using System;
using System.Reflection;
using static Towel.Syntax;
namespace Example
{
class Program
{
static void Main(string[] args)
{
@ZacharyPatten
ZacharyPatten / GenericMathematicalAddition.cs
Last active December 11, 2019 16:18
Generic Mathematics Example Using Runtime Compilation in C#
using System;
using System.Linq.Expressions;
using System.Numerics;
using static Towel.Syntax;
namespace Example
{
public class Program
{
static void Main(string[] args)