Skip to content

Instantly share code, notes, and snippets.

class WhoisLookup
{
private readonly string webApiBaseAddress = "http://api.hackertarget.com/whois/?q=";
public string HostToLookup { get; private set; }
public WhoisLookup(string hostToLookup)
{
HostToLookup = hostToLookup;
}
public class Money
{
public decimal Amount { get; private set; } = 20m;
public void doStuff()
{
Amount *= 2;
}
}
public class Person
{
// Example 1: manually implemented property
private string _name;
public string Name
{
get
{
return _name;
using System;
namespace ConsoleApplication
{
public class Program
{
static void Main()
{
Console.WriteLine(getWithTernaryOperator());
Console.WriteLine(getWithNullCoalescingOperator());
class Engine
{
public bool IsRunning { get; private set; }
public void Start() { }
public void Stop() { }
}
class Machine
{
public Engine Engine { get; }
public class Program
{
public static void Main(string[] args)
{
PowerOf2Example();
}
private static void PowerOf2Example()
{
var numbers = new List<int>() {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
class Person
{
public int Age { get; }
public string Name { get; }
public Person(int age, string name)
{
this.Age = age;
this.Name = name;
}
namespace LiskovSubstitutionPrinciple.Violation
{
public class Rectangle
{
protected int _width;
protected int _height;
public virtual int Height
{
get { return _height; }
namespace LiskovSubstitutionPrinciple.Tests
{
[TestFixture]
public class Violation
{
[Test]
public void RectangleIsOkay()
{
Rectangle rect = new Rectangle
{
namespace Open_Closed_Principle.Violation
{
public class AvgTemperatureReader
{
public double GetAverageTemperature(List<object> temperatureSensors)
{
double total = 0;
int count = 0;
foreach (var temperatureSensor in temperatureSensors.OfType<IndoorTemperatureSensor>())