Skip to content

Instantly share code, notes, and snippets.

View jskeet's full-sized avatar
💭
Very happily employed. I do not wish to hear from recruiters.

Jon Skeet jskeet

💭
Very happily employed. I do not wish to hear from recruiters.
View GitHub Profile
using System.Text.Json;
namespace ContosoCrafts.Website.Services;
public class JsonFileProductService
{
public IWebHostEnvironment WebHostEnvironment { get; }
private string JsonFileName =>
Path.Combine(WebHostEnvironment.WebRootPath, "data", "products.json");
public string LargestNumber(int num1, int num2) =>
num1 > num2 ? "number 1 is the greatest!"
: num2 > num1 ? "number 2 is the greatest!"
: "Both are equal!";
using Microsoft.FeatureManagement;
class Program
{
static void Main()
{
IFeatureManager featureManager = null;
if (featureManager.IsEnabledAsync(nameof(WidgetFeatureFlags.FeatureToggleABC)).Result)
{
Console.WriteLine("Running task with new toggle");
using System;
using System.Collections.Concurrent;
using System.Linq;
using System.Reflection;
public class MyEntity
{
public string Name;
public string MacAddress;
public bool IsIncredible;
using Newtonsoft.Json;
var a = new A("test");
var asJson = JsonConvert.SerializeObject(
a,
Formatting.None,
new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore
});
using System;
using System.Globalization;
var result = TimeZoneInfo.ConvertTime(DateTime.UtcNow, TimeZoneInfo.Local);
Console.WriteLine(result);
List<Item?> collection = new List<Item?>();
foreach (var item in collection)
{
if (item == null)
continue;
if (item.Field == "xyz")
{
Console.WriteLine("Found it");
}
}
using NUnit.Framework;
using System;
using System.Threading;
using System.Threading.Tasks;
namespace EventTest2;
public static class Extensions
{
private const int DEFAULT_HANDLE_POLLING_INTERVAL = 50; // ms
using System.Net.Sockets;
string host = "192.168.1.45";
int port = 5678;
byte[] getPowerCommand = { 0x81, 0x09, 0x04, 0x00, 0xff };
// Create two clients - these will connect immediately
var client1 = new TcpClient(host, port);
client1.NoDelay = true;
using System;
var foo = new Foo();
Console.WriteLine(foo.ToString());
public interface IFoo : IFormattable
{
}
public class Foo : IFoo