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
Stream stream = File.OpenRead("foo");
Console.WriteLine("Before using");
using (stream)
{
// Whatever...
}
Console.WriteLine("After using statement - variable is still in scope");
using System;
static class Test
{
private static void Foo(this string text)
{
Console.WriteLine(text);
}
static void Main()
using System;
interface IFoo
{
void DoWork()
{
Console.WriteLine("Default implementation");
}
}
public boolean setVal(int v) {
int oldVal = val;
val = v;
return oldVal != v;
}
using System;
using System.Threading;
struct Foo
{
private readonly int value;
public Foo(int value)
{
this.value = value;
import java.util.*;
import java.text.*;
public class Test {
public static void main(String[] args) throws Exception {
String text = "2020-05-05T09:30:00";
Locale locale = Locale.ROOT;
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(
"yyyy-MM-dd'T'HH:mm:ss", locale);
simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
using System;
class Program
{
static void Main(string[] args)
{
M("foo");
M(new object());
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Buffers" Version="4.5.1" />
<PackageReference Include="System.Memory" Version="4.5.4" />
using System;
using System.Collections.Generic;
class Program
{
static void Main()
{
CaptureLoopVariable(); // Prints 5 5 5 5 5
CaptureCopyOfLoopVariable(); // Prints 0 1 2 3 4
}
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
namespace LoopingEnumerable
{
public class Translation
{
public string TranslatedText { get; set; }