Skip to content

Instantly share code, notes, and snippets.

@markv12
markv12 / DelegateExamples.cs
Last active July 27, 2022 22:40
C# Action Func Predicate Examples
using System;
public class DelegateExamples
{
public void Run()
{
Action action1 = delegate { /*Do something*/ };
action1();
FunctionWithOnComplete(action1);
using System;
public class EventKeywordDemo
{
public event Action<int, bool> event1;
public Action<int, bool> action1;
public event EventHandler event2;
public delegate void SampleEventType(int param1, bool param2); //Equivalent to Action<int, bool>
// Decompiled with JetBrains decompiler
// Type: AsyncAwaitTest.Program
// Assembly: AsyncAwaitTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 52DF839B-9B18-40C2-9E30-2E3827E07665
// Assembly location: C:\code\AsyncAwaitTest\AsyncAwaitTest\bin\Debug\netcoreapp3.1\AsyncAwaitTest.dll
// Compiler-generated code is shown
using System;
using System.Diagnostics;
using System.IO;
using System;
namespace ClassVsStructDemo
{
class Program
{
static void Main(string[] args)
{
DemoStruct struct1 = new DemoStruct();
struct1.x = 4;
Hey everyone, today I'd like to go over the differences between classes and structs in C#
We'll start with how their memory is allocated.
Whenever you see a struct variable, the memory for that struct will be stored in the same location as the variable.
So if you have a struct variable in a function, the memory for that struct will be stored within that function's stack frame.
If you have an array of structs, the structs' memory will be stored within the array itself.
using System;
using UnityEngine;
//https://docs.unity3d.com/ScriptReference/AddComponentMenu.html
[AddComponentMenu("Demo/Script To Demo Unity Attributes")]
[RequireComponent(typeof(Rigidbody))]
[HelpURL("https://www.google.com/search?q=unity+attributes")]
[SelectionBase]
public class UnityAttrbuteDemo : MonoBehaviour
{
[Header("Serialization")]
// https://forum.unity.com/threads/clear-old-texture-references-from-materials.318769/
#define UPDATING_FLOAT_TO_INT
#if UNITY_EDITOR
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class MaterialPropertyCleaner : EditorWindow {
private const float REMOVE_BUTTON_WIDTH = 60;