This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using system; | |
using System.Runtime.CompilerServices; | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.WriteLine($"Data={Data}"); | |
} | |
public static string Data; | |
[ModuleInitializer] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class Weather | |
{ | |
public abstract Temperature GetTemperature(); | |
} | |
class Spain : Weather | |
{ | |
public override Celsius GetTemperature() => new Celsius(); | |
} | |
class USA : Weather | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Point point1 = new() { X = 1, Y = 2}; | |
Console.WriteLine(point1.ToString()); | |
public record Point | |
{ | |
public int X { get; init;} | |
public int Y { get; init;} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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;} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//C#8 | |
button.Click += (s, e) => {Message.Box.Show("Button clicked"); }; | |
//C#9 | |
button.Click += (_, _) => {Message.Box.Show("Button clicked"); }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
Console.WriteLine("Hello World!"); |
OlderNewer