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;
class Program
{
static void Main()
{
int yas;
yas=Convert.ToInt32(Console.ReadLine());
}
}
using Newtonsoft.Json;
class Data
{
public string Title { get; set; }
public DateTime SomeTimestamp { get; set; }
public List<int> Numbers { get; set; } = new List<int>();
}
class Program
private IEnumerable<EnumDescriptor> GetEnumDefinitions(IReadOnlyList<FileDescriptor> fileDescriptors) =>
fileDescriptors.SelectMany(GetEnumDefinitions);
private IEnumerable<EnumDescriptor> GetEnumDefinitions(FileDescriptor fileDescriptor) =>
fileDescriptor.EnumTypes.Concat(fileDescriptor.MessageTypes.SelectMany(GetEnumDefinitions));
private IEnumerable<EnumDescriptor> GetEnumDefinitions(MessageDescriptor messageDescriptor) =>
messageDescriptor.EnumTypes.Concat(messageDescriptor.NestedTypes.SelectMany(GetEnumDefinitions));
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");
}
}