Advertisement
bero_0401

Array List - Un/Boxing

Aug 19th, 2024
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.87 KB | Source Code | 0 0
  1. using System.Collections;
  2.  
  3. namespace CsharpStudy
  4. {
  5.     /*
  6.      * [ ArrayList ]
  7.      * - Definition
  8.      * - Boxing , UnBoxing
  9.      */
  10.     internal class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             ArrayList list = new ArrayList();
  15.             list.Add(1);
  16.             list.Add("string");
  17.             list.Add(true);
  18.             list.AddRange(new int[] { 1, 2, 3 });
  19.  
  20.             list.Remove(1);
  21.             // list.RemoveAt(1);
  22.             // list.RemoveRange(1, 2);
  23.  
  24.             foreach(object  o in list) {
  25.                 Console.WriteLine(o);
  26.             }
  27.  
  28.  
  29.             int x = 1;
  30.             #region boxing / unboxing
  31.  
  32.             // boxing
  33.             object o = x;
  34.  
  35.             //int y = o; xxx
  36.             // unboxing
  37.             int y = (int)o;
  38.            
  39.             #endregion
  40.  
  41.  
  42.  
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement