Skip to content

Instantly share code, notes, and snippets.

View geoffreymcgill's full-sized avatar

Geoffrey McGill geoffreymcgill

View GitHub Profile
Product product = new Product();
product.Name = "Apple";
product.ExpiryDate = new DateTime(2008, 12, 28);
product.Price = 3.99M;
product.Sizes = new string[] { "Small", "Medium", "Large" };
string output = JsonConvert.SerializeObject(product);
//{
// We need the Timer reference to have access to it in the callback
public static Timer timer;
// A flag of changing the Timer's due time and period
public static bool timerChanged;
public static void Main()
{
// The Timer callback
TimerCallback callback = (state) =>
var watch = Stopwatch.StartNew();
Console.WriteLine(watch.ElapsedMilliseconds);
Console.WriteLine("Waiting...");
Global.SetTimeout(() =>
{
Console.WriteLine(watch.ElapsedMilliseconds);
}, 2000);
var watch = System.Diagnostics.Stopwatch.StartNew();
Console.WriteLine(watch.ElapsedMilliseconds);
Thread.Sleep(2000); // Block for 2 seconds
Console.WriteLine(watch.ElapsedMilliseconds);
public class App
{
public static void Main()
{
Random rnd = new Random();
int lowerBound = 10;
int upperBound = 11;
int[] range = new int[10];
public class App
{
public static void Main()
{
Console.WriteLine("int.MaxValue: " + int.MaxValue);
Console.WriteLine("Factorial of 12: " + App.Factorial(12));
Console.WriteLine("Factorial of 13: " + App.Factorial(13)); // exceeds int.MaxValue
Console.WriteLine("long.MaxValue: " + long.MaxValue);
Console.WriteLine("Factorial of 20: " + App.Factorial(20));
long a = 1234567890;
long b = -9876543210;
// Long is quite long
Console.WriteLine(long.MinValue);
Console.WriteLine(long.MaxValue);
// Some long calculations
Console.WriteLine(long.MinValue + long.MaxValue);
Console.WriteLine(a * b);
Drive: "C"
Dir path: "\ParentDir\ChildDir"
Dir #1: "ParentDir"
Dir #2: "ChildDir"
File name: "Archive"
File ext: ".zip"
Drive: "D"
Dir path: ""
File name: "WithoutDir"
File ext: ".doc"
public class App
{
public static void Main()
{
App.ParseFilePath(@"C:\ParentDir\ChildDir\Archive.zip");
Console.WriteLine();
App.ParseFilePath(@"D:\WithoutDir.doc");
Console.WriteLine();
public class App
{
public static void Main()
{
// Match any word that starts with 'th', but not 'tho'
string pattern = @"\bth[^o]\w+\b";
string input = "thought thing though them through thus thorough this";
foreach (Match match in Regex.Matches(input, pattern))