This file contains 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
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); | |
//{ |
This file contains 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
// 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) => |
This file contains 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
var watch = Stopwatch.StartNew(); | |
Console.WriteLine(watch.ElapsedMilliseconds); | |
Console.WriteLine("Waiting..."); | |
Global.SetTimeout(() => | |
{ | |
Console.WriteLine(watch.ElapsedMilliseconds); | |
}, 2000); |
This file contains 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
var watch = System.Diagnostics.Stopwatch.StartNew(); | |
Console.WriteLine(watch.ElapsedMilliseconds); | |
Thread.Sleep(2000); // Block for 2 seconds | |
Console.WriteLine(watch.ElapsedMilliseconds); |
This file contains 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
public class App | |
{ | |
public static void Main() | |
{ | |
Random rnd = new Random(); | |
int lowerBound = 10; | |
int upperBound = 11; | |
int[] range = new int[10]; |
This file contains 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
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)); |
This file contains 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
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); |
This file contains 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
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" |
This file contains 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
public class App | |
{ | |
public static void Main() | |
{ | |
App.ParseFilePath(@"C:\ParentDir\ChildDir\Archive.zip"); | |
Console.WriteLine(); | |
App.ParseFilePath(@"D:\WithoutDir.doc"); | |
Console.WriteLine(); |
This file contains 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
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)) |