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.
Snippets
Custom Events & Handling
CustomEventArgs.cs
1 public class CustomEventArgs : EventArgs
2 {
3 private readonly object item;
4
5 public object Item
6 {
7 get { return item; }
8 }
9
10 public CustomEventArgs(object item)
11 {
12 this.item = item;
13 }
14 }
Instance.cs
1 public delegate void NotifyCustomEvent(object sender, CustomEventArgs e);
2 public event NotifyCustomEvent CustomEvent;
3
4 private void RaiseCustomEvent(obj sender, obj item)
5 {
6 CustomEvent?.Invoke(sender, new CustomEventArgs(item));
7 }
InstanceOwner.cs
1 public InsanceOwner()
2 {
3 Instance instance = new instance();
4 instance.CustomEvent += new Instance.NotifyCustomEvent(CustomEventHandler);
5 }
6
7 public void CustomEventHandler(obj sender, CustomEventArgs e)
8 {
9
10 }
Number Remap Class
1 public static class Remap
2 {
3 private static double Map(double value, double fromSource, double toSource, double fromTarget, double toTarget)
4 {
5 return (value - fromSource) / (toSource - fromSource) * (toTarget - fromTarget) + fromTarget;
6 }
7 }