Nicolas PastorellyIntroduction à C #Principaux élément différentiablesPar rapport à Java1Modèle Objet • Les types de bases ne peuvent pas être utilisés comme des objets en JavaInteger i_ref = new Integer(7);List l = ...l.add( i_ref );…… i_ref.intValue();• C# : boxing & unboxingint i = 123; Heapobject o = i;int j = (int)o;123iSystem.Int32o123123jStack2Les propriétésPublic class Test{// donnée privée.private int m_number = 0;[Description(“Un entier non négatif !")]public int Number{// accesseurs du champ privéTest T = new Test();get {T.Number= -2;if (m_number < 0) return 0;return m_number;}set {Int I = T.Number + 1;if (value < 0) m_number = 0;else m_number = value;}}}3Les indexerspublic class ListBox: Control{private string[] items;public string this[int index] {get { ListBox listBox = new ListBox();return items[index];}set { listBox[0] = "hello";items[index] = value;Repaint(); Console.WriteLine(listBox[0]);}}}4Les classes non extensiblessealed class Student{string fname;string lname;int uid;void attendClass() {}}? (final Java)5Les NameSpacesusing System;namespace Company{public class MyClass{ /* Company. */int x;void doStuff(){}}namespace Carnage4life{public class MyOtherClass{ /* Company.Carnage4life.MyOtherClass */int y;void doOtherStuff(){}public static void Main(string[] args){Console.WriteLine("Hey, I can nestnamespaces");}}// class MyOtherClass}// namespace Carnage4life}// ...
Voir