Advertisement
bero_0401

Generic List / Dictionary

Aug 19th, 2024 (edited)
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.91 KB | Source Code | 0 0
  1. using System.Collections;
  2.  
  3. namespace CsharpStudy
  4. {
  5.     /*
  6.      * [ Generic List ]
  7.      * [ Dictionary ]
  8.      */
  9.     internal class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             // list
  14.             var list = new List<int>();
  15.             list.Add(1);
  16.             list.AddRange(new[] { 2, 3 });
  17.             list.Remove(1);
  18.             list.IndexOf(2);
  19.  
  20.  
  21.             // Dictionary
  22.             var dict = new Dictionary<string, string>();
  23.             dict.Add("Email", "[email protected]");
  24.             dict.Add("password", "12345");
  25.  
  26.             if (dict.ContainsKey("Email"))
  27.                 Console.WriteLine(dict["Email"]);
  28.  
  29.             if (!dict.ContainsKey("Email"))
  30.                 dict.Add("Email", "[email protected]");
  31.  
  32.             var isContain = dict.TryGetValue("password" , out var value);
  33.  
  34.             Console.WriteLine(value + ' ' + isContain);
  35.  
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement