Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 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.  
  7. namespace ConsoleApp1
  8. {
  9. struct Persoana
  10. {
  11. public string nume;
  12.  
  13. }
  14. class Program
  15. {
  16. static void Modificare(Persoana pers)
  17. {
  18. pers = new Persoana(); //aici nu se poate aloca ceva pe stiva, atunci punem pe heap obiectul persoana;
  19. pers.nume = "Modificat";
  20. }
  21. static void Main(string[] args)
  22. {
  23. int i = 7;
  24. 13.ToString();
  25.  
  26. // Persoana p; //aloca pe stiva spatiul necesar pentru adresa si atat
  27. // p = new Persoana();
  28.  
  29. // Persoana p = new Persoana();
  30. //daca punem struct sau enum se aloca spatiu pe stiva
  31. //daca tipul este class se aloca pe stiva doar o adresa
  32.  
  33. // new Persoana(); //daca apelam new pt un value type nu aloca, doar aloca pe stiva val respectiva si apeleaza constructorul
  34. // de ce ne intereseaza ce se aloca pe stiva?
  35.  
  36.  
  37. //Persoana p = new Persoana();
  38. //p.nume = "Ion";
  39. //Persoana q = p;
  40. //q.nume = "Maria";
  41. //Console.WriteLine(p.nume);
  42. //Console.WriteLine(q.nume);
  43.  
  44. Persoana p = new Persoana();
  45. p.nume = "Ion";
  46. Modificare(p);
  47. Console.WriteLine(p.nume);
  48.  
  49. String test = "Ana are mere.";
  50. String altTest = test;
  51.  
  52. test.Replace("Ana", "Ion"); //intoarce un string unde inlocuieste Ana cu Ion, dar test nu se modifica
  53.  
  54.  
  55. Console.WriteLine(test[0]);
  56. Console.WriteLine(test);
  57. Console.WriteLine(altTest);
  58.  
  59.  
  60. }
  61.  
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement