qui ho creato l'appuntamento variabile di tipo Pair<Pair <int, int>, String>
Vorrei creare un valore di questo tipo e assegnarlo all'appuntamento.
Qualcuno potrebbe aiutarmi? Sono nuovo di C # e programmazione.
Pair< Pair<int, int>, String> appointment = new Pair<Pair<int,int>,String>;
risposte:
3 per risposta № 1Supponendo che Pair
ha un costruttore con due argomenti
Pair<Pair<int,int>,string> appointment = new Pair<Pair<int,int>,string>(
new Pair<int,int>(x, y),
"hello"
);
o più conciso
var appointment = new Pair<Pair<int,int>,string>(
new Pair<int,int>(x, y),
"hello"
);
o con inizializzatori di oggetti (supponendo Pair
ha due proprietà denominate Arg1
e Arg2
)
var appointment = new Pair<Pair<int,int>,string> {
Arg1 = new Pair<int,int> { Arg1 = x, Arg2 = y),
Arg2 = "hello"
};
o se vuoi creare un vuoto Pair
var appointment = new Pair<Pair<int,int>,string>();
0 per risposta № 2
Supponendo che la classe Pair abbia le seguenti proprietà pubbliche con i setter pubblici:
public Pair<T, T> Nested { get; set; }
public string Name { get; set ; }
allora anche tu puoi fare:
var appoinment = new Pair<Pair<int,int>,string>
{
Nested = new Pair<int,int>(1, 2),
Name = "Eric"
};