10
mars
2007
C’est quand même vraiment bien C# 3
mars
2007
Grâce à C# 3.0, le code suivant :
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
List<Personne> list = new List<Personne>();
list.Add(new Personne("Z", "A"));
list.Add(new Personne("A", "Z"));
list.Add(new Personne("A", "A"));
bindingSource1.DataSource = list;
}
}
public class Personne
{
private string _nom;
private string _prenom;
public Personne(string nom, string prenom)
{
_nom = nom;
_prenom = prenom;
}
public string Nom
{
get
{
return _nom;
}
set
{
_nom = value;
}
}
public string Prenom
{
get
{
return _prenom;
}
set
{
_prenom = value;
}
}
public override string ToString()
{
return Nom + " " + Prenom;
}
}
{
public Form1()
{
InitializeComponent();
List<Personne> list = new List<Personne>();
list.Add(new Personne("Z", "A"));
list.Add(new Personne("A", "Z"));
list.Add(new Personne("A", "A"));
bindingSource1.DataSource = list;
}
}
public class Personne
{
private string _nom;
private string _prenom;
public Personne(string nom, string prenom)
{
_nom = nom;
_prenom = prenom;
}
public string Nom
{
get
{
return _nom;
}
set
{
_nom = value;
}
}
public string Prenom
{
get
{
return _prenom;
}
set
{
_prenom = value;
}
}
public override string ToString()
{
return Nom + " " + Prenom;
}
}
est devenu
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
bindingSource1.DataSource = new List<Personne>() { new Personne { Nom = "Z", Prenom = "A" }, new Personne { Nom = "A", Prenom = "Z" }, new Personne { Nom = "A", Prenom = "A" } };
}
}
public class Personne
{
public string Nom { get; set; }
public string Prenom { get; set; }
public override string ToString()
{
return Nom + " " + Prenom;
}
}
{
public Form1()
{
InitializeComponent();
bindingSource1.DataSource = new List<Personne>() { new Personne { Nom = "Z", Prenom = "A" }, new Personne { Nom = "A", Prenom = "Z" }, new Personne { Nom = "A", Prenom = "A" } };
}
}
public class Personne
{
public string Nom { get; set; }
public string Prenom { get; set; }
public override string ToString()
{
return Nom + " " + Prenom;
}
}