Advertisement
Pro_Unit

DictionaryExample

Dec 29th, 2018
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.85 KB | None | 0 0
  1. using System.Collections.Generic;
  2. using System;
  3.  
  4. public class DictionaryExample
  5. {
  6.     [Serializable]
  7.     public class MyCustomClass
  8.     {
  9.         public float a;
  10.         public float b;
  11.     }
  12.     public Dictionary<MyCustomClass, List<float>> dict;
  13.  
  14.     public void SomeMethod ()
  15.     {
  16.         dict = new Dictionary<MyCustomClass, List<float>> ();
  17.         dict.Add (
  18.             new MyCustomClass ()
  19.             {
  20.                 a = 1, b = 2
  21.             },
  22.             new List<float> ()
  23.             {
  24.                 10,
  25.                 20,
  26.                 30,
  27.                 40,
  28.                 50
  29.             });
  30.  
  31.         MyCustomClass key = new MyCustomClass () { a = 1, b = 2 };
  32.  
  33.         List<float> NeededValue = null;
  34.  
  35.         dict.TryGetValue (key, out NeededValue);
  36.  
  37.         // NeededValue = null; How avoid this ????
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement