Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace TargetType
- {
- internal class Program
- {
- class Classe1
- {
- public Classe1(int n, string s) { }
- public void unMetodo(Action<string> lambda)
- {
- lambda("ciao");
- }
- }
- class Classe2
- {
- Classe1 objClasse1 = new(3, "ciao");
- public Classe2(Classe1 obj) { }
- }
- class Madre { }
- class Figlia1 : Madre { }
- class Figlia2 : Madre { }
- static void Main(string[] args)
- {
- Random rnd = new Random();
- Madre m = rnd.Next(1,2)==0 ? new Figlia1() : new Figlia2 ();
- // targed typed new
- Classe1 oggetto = new(5, "ciao");
- Classe2 oggettoC2 = new(new(3, "Ciao"));
- //oggetto.unMetodo((string s) => Console.WriteLine( oggettoC2.ToString()));
- const int i = 999;
- oggetto.unMetodo(static (string s) => Console.WriteLine(i)); ;
- Console.WriteLine(i);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement