Skip to content

Instantly share code, notes, and snippets.

using system;
using System.Runtime.CompilerServices;
class Program
{
static void Main(string[] args)
{
Console.WriteLine($"Data={Data}");
}
public static string Data;
[ModuleInitializer]
using system;
using System.Collections.Generic;
IEnumerator<string> colors = new List<string> {"blue", "red", "green"}.GetEnumerator();
foreach (var colors in colors)
{
Console.WriteLine($"{color} is my favorite color");
}
public static class Extensions
{
public static IEnumerator<T> GetEnumerator<T>(this IEnumerator<T> enumerator) => enumerator;
abstract class Weather
{
public abstract Temperature GetTemperature();
}
class Spain : Weather
{
public override Celsius GetTemperature() => new Celsius();
}
class USA : Weather
{
Point point1 = new() { X = 1, Y = 2};
Console.WriteLine(point1.ToString());
public record Point
{
public int X { get; init;}
public int Y { get; init;}
}
Point point1 = new() { X = 1, Y = 2};
Point point2 = point1 with { Y = 4};
Console.WriteLine(point1.ToString());
public record Point
{
public int X { get; init;}
public int Y { get; init;}
}
Point point1 = new(1, 2);
Console.WriteLine(point1.ToString());
Point point2 = new(1, 2)};
Console.WriteLine(point1.Equals(point2));
public record Point
{
public int X { get;}
public int Y { get;}
public Point(int x, int y) => (X, Y) = (x, y);
}
//C#8
button.Click += (s, e) => {Message.Box.Show("Button clicked"); };
//C#9
button.Click += (_, _) => {Message.Box.Show("Button clicked"); };
Point point = new() {X = 1, Y = 2};
Console.WriteLine($"point:({point1.X}, {point.Y})");
public class Point
{
public int X { get; set; }
public int Y { get; set; }
}
Point point = new(1, 2);
Console.WriteLine($"point:({point1.X}, {point.Y})");
public class Point{
public int X { get; }
public int Y { get; }
public Point(int x, int y) => (X, Y) = (x, y);
}
using System;
Console.WriteLine("Hello World!");