Advertisement
Danielos168

Diffrence between class and struct

Feb 26th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.33 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.IO;
  7.  
  8.  
  9.  
  10. namespace Daniel_Kazarnowicz_1
  11. {
  12.     public class klasa
  13.     {
  14.  
  15.         public int wartosc;
  16.         public void zmien(int nowa)
  17.         {
  18.             wartosc = nowa;
  19.         }
  20.         public void wyswietl()
  21.         {
  22.             Console.WriteLine("wartosc: {0} ", wartosc);
  23.         }
  24.     }
  25.     class Program
  26.     {
  27.         static void Podwoj(struktura s)
  28.         {
  29.             s.wartosc = s.wartosc * 2;
  30.            
  31.         }
  32.         static void Podwoj1(klasa k)
  33.         {
  34.             k.wartosc = k.wartosc * 2;
  35.         }
  36.         static void Main(string[] args)
  37.         {
  38.             struktura s = new struktura();
  39.             s.wyswietl();
  40.             s.zmien(200);
  41.             Podwoj(s);
  42.             s.wyswietl();
  43.             klasa k = new klasa();
  44.             k.wyswietl();
  45.             k.zmien(201);
  46.             Podwoj1(k);
  47.             k.wyswietl();
  48.             Console.ReadKey();
  49.  
  50.         }
  51.     }
  52.     struct struktura
  53.     {
  54.  
  55.         public int wartosc;
  56.         public void zmien(int nowa)
  57.         {
  58.             wartosc = nowa;
  59.         }
  60.         public void wyswietl()
  61.         {
  62.             Console.WriteLine("wartosc: {0} ", wartosc);
  63.         }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement