#lang en <> = Description = The snippets on this wikipage are written for the .NET Framework v4.0 and higher, but most probably work in older versions. Most will, however not work for .NET Core and .NET Standard. == Package Specific snippits == || '''Package''' || '''Description''' || || [[/Colore|Colore]] || C# Library for Razer Chroma's SDK || = Snippets = == override GetHashCode() == {{{#!highlight c# public override int GetHashCode() { int hash = 17; hash = hash * 23 + intA; hash = hash * 23 + intB; hash = hash * 23 + objectC.GetHashCode(); return hash; } }}} == Number Remap Class == {{{#!highlight c# public static class Remap { private static double Map(double value, double fromSource, double toSource, double fromTarget, double toTarget) { return (value - fromSource) / (toSource - fromSource) * (toTarget - fromTarget) + fromTarget; } } }}} == Custom Events & Handling == !CustomEventArgs.cs {{{#!highlight c# public class CustomEventArgs : EventArgs { private readonly object item; public object Item { get { return item; } } public CustomEventArgs(object item) { this.item = item; } } }}} Instance.cs {{{#!highlight c# public delegate void NotifyCustomEvent(object sender, CustomEventArgs e); public event NotifyCustomEvent CustomEvent; private void RaiseCustomEvent(obj sender, obj item) { CustomEvent?.Invoke(sender, new CustomEventArgs(item)); } }}} !InstanceOwner.cs {{{#!highlight c# public InsanceOwner() { Instance instance = new instance(); instance.CustomEvent += new Instance.NotifyCustomEvent(CustomEventHandler); } public void CustomEventHandler(obj sender, CustomEventArgs e) { //Handle that custom shit } }}} == IComparable Class == {{{#!highlight c# public class Mission : IComparable, IComparable { public string Name { get; private set; } public DateTime LaunchDate { get; private set; } public DateTime ReturnDate { get; private set; } public string SpaceShip { get; private set; } public List Astronauts { get; private set; } public Mission(string name, DateTime launchDate, DateTime returnDate, string spaceShip) { Astronauts = new List(); Name = name; LaunchDate = launchDate; ReturnDate = returnDate; SpaceShip = spaceShip; } public int CompareTo(Mission other) { if (ReferenceEquals(this, other)) return 0; if (ReferenceEquals(null, other)) return 1; int nameComparison = string.Compare(Name, other.Name, StringComparison.Ordinal); if (nameComparison != 0) return nameComparison; int launchDateComparison = LaunchDate.CompareTo(other.LaunchDate); if (launchDateComparison != 0) return launchDateComparison; int returnDateComparison = ReturnDate.CompareTo(other.ReturnDate); if (returnDateComparison != 0) return returnDateComparison; return string.Compare(SpaceShip, other.SpaceShip, StringComparison.Ordinal); } public int CompareTo(object obj) { if (ReferenceEquals(null, obj)) return 1; if (ReferenceEquals(this, obj)) return 0; if (!(obj is Mission)) throw new ArgumentException($"Object must be of type {nameof(Mission)}"); return CompareTo((Mission) obj); } } }}}