Skip to content

Instantly share code, notes, and snippets.

@crgrieve
crgrieve / DiscordWebhookComposer.cs
Created October 17, 2020 09:26
Umbraco Discord Webhook
using System;
using System.IO;
using System.Net;
using System.Web.Script.Serialization;
using Umbraco.Core;
using Umbraco.Core.Composing;
using Umbraco.Core.Services.Implement;
namespace WebhooksExample.Events
{
@crgrieve
crgrieve / Program.cs
Created December 12, 2020 11:54
Traditional Hello World Program.cs
using System;
namespace dotNet5HelloWorld
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
@crgrieve
crgrieve / Program.cs
Last active December 12, 2020 14:52
Top Level Program Hello World
using System;
Console.WriteLine("Hello World!");
@crgrieve
crgrieve / Program.cs
Created December 12, 2020 12:33
Top Level Program Minimal Hello World
System.Console.WriteLine("Hello World!");
@crgrieve
crgrieve / Program.cs
Created December 12, 2020 12:39
Top Level Program with method defined
using System;
Console.WriteLine(GetMessage("Glasgow"));
string GetMessage(string meetupName)
{
return String.Format("Welcome to the {0} meetup!", meetupName);
}
@crgrieve
crgrieve / Program.cs
Created December 12, 2020 13:43
Top Level Program with class
using System;
var glasgowMeetup = new Meetup("Glasgow", "Umbraco");
Console.WriteLine(GetMessage(glasgowMeetup));
string GetMessage(Meetup meetup)
{
return String.Format("Welcome to the {0} {1} meetup!", meetup.City, meetup.Topic);
}
@crgrieve
crgrieve / Meetup.cs
Created December 23, 2020 14:26
C# 9 init properties
public record Meetup
{
public string City { get; init; }
public string Topic { get; set; }
}
@crgrieve
crgrieve / Program.cs
Created December 23, 2020 14:30
C# 9 init only properties
using System;
var glasgowMeetup = new Meetup() {
City ="Glasgow",
Topic = ".Net"
};
Console.WriteLine(glasgowMeetup);
public record Meetup
@crgrieve
crgrieve / Program.cs
Created December 23, 2020 14:35
C# 9 init properties, error example.
using System;
var glasgowMeetup = new Meetup() {
City ="Glasgow",
Topic = ".Net"
};
glasgowMeetup.Topic = "Umbraco";
glasgowMeetup.City = "Edinburgh";
@crgrieve
crgrieve / Program.cs
Last active December 23, 2020 14:47
C# 9 init properties using "with"
using System;
var glasgowMeetup = new Meetup() {
City ="Glasgow",
Topic = ".Net"
};
var edinburghMeetup = glasgowMeetup with { City="Edinburgh" };
glasgowMeetup.Topic = "Umbraco";