pborawski

C# tablica obiektow.

Mar 12th, 2012
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.83 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ConsoleApplication6
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             Kot k1 = new Kot(10);
  13.             Kot k2 = new Kot();
  14.             Kot[] k3 = new Kot[3]; // puste referencje, nie tworza sie obiekty
  15.             // Musimy stworzyc obiekty za pomoca fora
  16.             for (int i = 0; i < 3; i++  )
  17.             {
  18.                 k3[i] = new Kot();
  19.             }
  20.            
  21.             Console.WriteLine(k3[1].Il_wasow);
  22.             Console.ReadKey();
  23.         }
  24.     }
  25.     class Kot
  26.     {
  27.         public int Il_wasow;
  28.         public Kot(int ilwasow)
  29.         {
  30.             Il_wasow = ilwasow;
  31.         }
  32.         public Kot()
  33.         {
  34.             Il_wasow = 12;
  35.         }
  36.  
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment