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 System.Diagnostics; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace StackAllocVsHeapAlloc | |
{ | |
public static class Sandbox |
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
// Creates new instance of a class by name (string). | |
public IClass GetDataSource(string className) | |
{ | |
// Should handle case where the className does not exist in dictionary. | |
// Lookup table that maps class string names to a constructor action. | |
var classDictonary = new Dictionary<string, Func<IClass>> | |
{ | |
{ "ClassA", () => new ClassA()}, | |
{ "ClassB", () => new ClassB()}, |
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
// Fixes error: The null value cannot be assigned to a member with type System.Decimal which is a non-nullable value type. | |
// In the case where none of the navigation property's StringPropA properties match a null will returned. | |
// .Sum() will throw an error if you try to sum null so we replace the null with a default value using .DefaultIfEmpty() | |
var total = Parent | |
.Where(x => x.NavigationProperty.StringPropA == "Foo") | |
.Select(x => x.DecimalPropB) | |
.DefaultIfEmpty(0) | |
.Sum() |
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
var duplicates = this.primaryJobs | |
.Select(x => new { Foo = x.Bar }) | |
.GroupBy(x => x.Foo) | |
.Select(x => new { Foo = x.Key, Count = x.Count() }) | |
.Where(x => x.Count > 1) | |
.Select(x => x.Foo) | |
.Aggregate((i,j) => i + ',' + j); | |
// "A, B, C" |
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 NLog; | |
using NLog.Config; | |
using NLog.Targets; | |
using NLog.Targets.Wrappers; | |
using System.Diagnostics; | |
namespace Web.App_Start | |
{ | |
/// <summary> | |
/// Programmatically configure NLog. |
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.Web; | |
using System.Web.Mvc; | |
namespace Infrastructure | |
{ | |
/// <summary> | |
/// MVC attribute that redirects non HTTPS requests to a HTTPS URI. | |
/// </summary> | |
public class RedirectToHTTPSAttribute : ActionFilterAttribute |
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.Net; | |
using System.Net.Http; | |
using System.Text; | |
using System.Web.Http.Controllers; | |
using System.Web.Http.Filters; | |
namespace Infrastructure | |
{ | |
/// <summary> |
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
public class ImplementingICloneable : ICloneable | |
{ | |
/// <summary> | |
/// Returns a clone of the current object. | |
/// </summary> | |
public ImplementingICloneable Clone() | |
{ | |
return (ImplementingICloneable)this.MemberwiseClone(); // MemberwiseClone() only creates a shallow copy. | |
} |
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
[TestMethod] | |
public void Name_When_Expect() | |
{ | |
// Arrange | |
var userName = Environment.UserName; | |
// Act | |
// Assert | |
} |
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
static const int values[] = {0,1,2,3,4,5,6,7,8,9}; | |
vector<int> v (values, values + sizeof(values) / sizeof(values[0]) ); | |
// Using C++11 ranged-based for loop | |
std::stringstream ss; | |
for (int n : v) | |
ss << n; | |
Assert::IsTrue(ss.str() == "0123456789"); | |
ss.str(""); ss.clear(); // clear string stream |