Advertisement
fcamuso

Da c# 9 a 10 lezione 1

Feb 24th, 2022
1,169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.64 KB | None | 0 0
  1. using System;
  2.  
  3. namespace records
  4. {
  5.  
  6.   record class Automobile(string Marca, string Modello);
  7.  
  8.   record struct ClienteRecordStruct(string Cognome, string Nome);
  9.  
  10.   struct ClienteStruct{
  11.    
  12.     public ClienteStruct(string cognome, string nome)
  13.     {
  14.       Cognome = cognome;
  15.       Nome = nome;  
  16.     }
  17.  
  18.     public string Cognome { get; set; }
  19.     public string Nome { get; set; }
  20.   }
  21.  
  22.   internal class Program
  23.   {
  24.     static void Main(string[] args)
  25.     {
  26.       ClienteStruct c1Struct = new ("De'Paperoni", "Paperon");
  27.       ClienteStruct c2Struct = new ("De'Paperoni", "Paperon");
  28.  
  29.       c1Struct.Cognome = "De Paperoni";
  30.  
  31.       ClienteRecordStruct c1rs = new ClienteRecordStruct("De'Paperoni", "Paperon");
  32.       ClienteRecordStruct c2rs = new ClienteRecordStruct("De'Paperoni", "Paperon");
  33.  
  34.       c1rs.Cognome = "sdfsd";
  35.  
  36.       //Console.WriteLine(c1Struct == c2Struct);
  37.       Console.WriteLine(c1rs == c2rs);
  38.       Console.WriteLine(c1rs != c2rs);
  39.  
  40.       //(string cognome, string nome) = c1Struct;
  41.       var (cognome, nome) = c1rs;
  42.       Console.WriteLine($"{cognome} {nome}");  
  43.      
  44.  
  45.  
  46.  
  47.  
  48.     //Automobile auto1 = new Automobile("Fiat", "500");
  49.     //Automobile auto2 = new Automobile("Fiat", "500");
  50.  
  51.     //Console.WriteLine(auto1 == auto2); //true
  52.  
  53.     ////auto1.Marca = "Mercedes";  NO, immutable!
  54.  
  55.     //Console.WriteLine(auto1.ToString());
  56.  
  57.     //Automobile auto3 = auto1 with { };
  58.     //auto3 = auto3 with { Marca = "Honda" };
  59.  
  60.     //Console.WriteLine($"{auto1.Marca} {auto3.Marca}");
  61.  
  62.     //var (marca, modello) = auto3;
  63.     //Console.WriteLine($"{marca}, {modello}");
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.     }
  72.   }
  73. }
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement