0
classAbc{<br />  public intA();<br />}<br />Abco =newAbc();<br />intn = o.A();<br />o.Foo();<br />
intnumber = 42;<br />number = 1.0;<br />intnumber = 42;<br />number = (int)1.0;<br />
intnumber = 42;<br />number = “123”;<br />intnumber = 42;<br />number = int.Parse(“123”);<br />
42 + 8.0 + “123”;<br />
int[] array = newint[5];<br />int elemento = array[100];<br />A oggetto = (A)newB();<br />
dynamic o = newA();<br />o.Foo();<br />
var text = “pippo”;<br />varnumber = random.Next();<br />varresult = 24.0 * 2;<br />
unsafe{<br />int*p = newint[100];<br />    p[100] = 0; //boom<br />}<br />
“sono una stringa”<br />string ciao = “ciao”.Trim();<br />
public classMyClass {<br />int_myNumber;<br />public intYourNumber;<br />}<br />
public classMyClass {<br />int_myNumber;<br />public voidSetNumber(int v){<br />if(v == 0)<br />thrownewException();<br />...
MyClassc = newMyClass();<br />c.SetNumber(100);<br />
public classMyClass {<br />int_myNumber;<br />public intNumber {<br />get {<br />return_myNumber;<br />        }<br />    ...
public classMyClass {<br />int_myNumber;<br />public intNumber {<br />get {<br />return_myNumber;<br />        }<br />set ...
MyClassc = newMyClass();<br />c.Number = 100;<br />intnumber = c.Number;<br />
public classMyClass {<br />public event<br />EventHandlerNumberChanged;<br />public intNumber {<br />set {<br />_myNumber ...
MyClassc = newMyClass();<br />c.NumberChanged += EventHandler(Gestore);<br />c.Number = 100;<br />private voidGestore(obje...
public classSystem.Object {<br />public virtualobjectEquals(objectobj);<br />    public virtualintGetHashCode();<br />publ...
public classMyClass {<br />File_myFile;<br />publicMyClass(){<br />_myFile = newFile(…);<br />  }<br />publicMyClass(strin...
MyClass c1 = newMyClass();<br />MyClass c2 = newMyClass(“nome”);<br />
public classMyClass {<br />File_myFile;<br />//...<br />~MyClass(){<br />    _myFile.Close();<br />  }<br />}<br />
public classContenitore {<br />int_number;<br />public overridestringToString(){<br />return “Numero: ” + _number;<br />  ...
public classBase {<br />public virtualintA(){<br />return42;<br />  }<br />public stringB(){<br />return “don’t panic”;<br...
public interface IFoo{<br />int Bar();<br />stringBaz(intarg);<br />}<br />
public abstractclassFoo{<br />public abstractint Bar();<br />public virtualstringBaz(intarg){<br />return “baz”;<br />  }<...
IDisposable<br />public classMyClass : IDisposable {<br />File_myFile;<br />~MyClass(){<br />    _myFile.Close();<br />  }...
using(var file = newMyFile()){<br />// ...<br />}<br />// oggetto distrutto<br />
delegate stringFiltro(string s);<br />FiltrofiltraSpazi = delegate(string s){<br />returns.Replace(“ ”, “”);<br />}<br />f...
delegate stringFiltro(string s);<br />FiltrofiltraSpazi =<br />s => s.Replace(“ ”, “”);<br />
ThreadPool.QueueUserWorkItem(o => {<br />// operazione lunga<br />}, null);<br />
public staticclassStringExtensions {<br />  public staticstringGreet(thisstring s){<br />return“Ciao ” + s + “!”;<br />  }...
DateTime<br />
public staticstringToIso8601(thisDateTimeval) {<br />returnval.ToString(@"yyyy-MM-ddTHH:mm:ss.ff",<br />CultureInfo.Invar...
newMyClass(“ciao”, 10);<br />newMyClass<int>(100);<br />
public classWidgetContainer {<br />object[] _array;<br />public voidAdd(Widgetinstance){ ... }<br />public WidgetGet(intin...
Attribute<br />public MyAttribute : Attribute {<br />public intCount { get; set; }<br />}<br />[My(Count = 10)]<br />publi...
varc = newMyClass();<br />varattrs = c.GetType()<br />    .GetCustomAttributes(typeof(MyAttribute), true);<br />varattr = ...
IEnumerable<T><br />IEnumerator<T> {<br />  T Current { get; }<br />boolMoveNext();<br />void Reset();<br />}<br />IEnumer...
IEnumerable<T><br />int[] fibo = new { 0, 1, 1, 2, 3, 5, 8 };<br />foreach(var i infibo){<br />Console.Write(i);<br />}<br...
IList<T><br />IList<int> fibo = new { 0, 1, 1, 2, 3 };<br />fibo[2] = 2;          //0, 1, 2, 2, 3<br />int c = fibo.Count;...
System.Collections.Generic<br />List<T> : IList<T><br />Dictionary<K,T> : IDictionary<K,T><br />LinkedList<T> : ICollectio...
System <br />System.Collections<br />System.Diagnostics<br />System.Globalization<br />System.IO <br />System.Net<br />Sys...
System.Linq<br />(System.Core.dll)<br />
varnums = from n inEnumerable.Range(0, 100)<br />letsquare = n * n<br />wheresquare >= 49<br />select n;<br />// 7 8 9 10 ...
Introduzione a C#
Upcoming SlideShare
Loading in...5
×

Introduzione a C#

1,276

Published on

Breve introduzione a C# 4 ed alle sue feature più importanti/interessanti.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,276
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
10
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Introduzione a C#"

  1. 1.
  2. 2.
  3. 3.
  4. 4.
  5. 5.
  6. 6. classAbc{<br /> public intA();<br />}<br />Abco =newAbc();<br />intn = o.A();<br />o.Foo();<br />
  7. 7. intnumber = 42;<br />number = 1.0;<br />intnumber = 42;<br />number = (int)1.0;<br />
  8. 8. intnumber = 42;<br />number = “123”;<br />intnumber = 42;<br />number = int.Parse(“123”);<br />
  9. 9. 42 + 8.0 + “123”;<br />
  10. 10. int[] array = newint[5];<br />int elemento = array[100];<br />A oggetto = (A)newB();<br />
  11. 11. dynamic o = newA();<br />o.Foo();<br />
  12. 12. var text = “pippo”;<br />varnumber = random.Next();<br />varresult = 24.0 * 2;<br />
  13. 13. unsafe{<br />int*p = newint[100];<br /> p[100] = 0; //boom<br />}<br />
  14. 14.
  15. 15. “sono una stringa”<br />string ciao = “ciao”.Trim();<br />
  16. 16. public classMyClass {<br />int_myNumber;<br />public intYourNumber;<br />}<br />
  17. 17. public classMyClass {<br />int_myNumber;<br />public voidSetNumber(int v){<br />if(v == 0)<br />thrownewException();<br />_myNumber = v;<br /> }<br />}<br />
  18. 18. MyClassc = newMyClass();<br />c.SetNumber(100);<br />
  19. 19. public classMyClass {<br />int_myNumber;<br />public intNumber {<br />get {<br />return_myNumber;<br /> }<br /> }<br />}<br />
  20. 20. public classMyClass {<br />int_myNumber;<br />public intNumber {<br />get {<br />return_myNumber;<br /> }<br />set {<br />_myNumber = value;<br /> }<br /> }<br />}<br />
  21. 21. MyClassc = newMyClass();<br />c.Number = 100;<br />intnumber = c.Number;<br />
  22. 22. public classMyClass {<br />public event<br />EventHandlerNumberChanged;<br />public intNumber {<br />set {<br />_myNumber = value;<br />NumberChanged(this, null);<br /> }<br />}<br />
  23. 23. MyClassc = newMyClass();<br />c.NumberChanged += EventHandler(Gestore);<br />c.Number = 100;<br />private voidGestore(objectsender,<br />EventArgsargs){<br />Console.WriteLine(“Numero cambiato.”);<br />}<br />
  24. 24. public classSystem.Object {<br />public virtualobjectEquals(objectobj);<br /> public virtualintGetHashCode();<br />publicTypeGetType();<br />public virtualstringToString();<br />}<br />
  25. 25. public classMyClass {<br />File_myFile;<br />publicMyClass(){<br />_myFile = newFile(…);<br /> }<br />publicMyClass(stringname){<br />_myFile = File.Open(name);<br /> }<br />}<br />
  26. 26. MyClass c1 = newMyClass();<br />MyClass c2 = newMyClass(“nome”);<br />
  27. 27. public classMyClass {<br />File_myFile;<br />//...<br />~MyClass(){<br /> _myFile.Close();<br /> }<br />}<br />
  28. 28. public classContenitore {<br />int_number;<br />public overridestringToString(){<br />return “Numero: ” + _number;<br /> }<br />}<br />
  29. 29. public classBase {<br />public virtualintA(){<br />return42;<br /> }<br />public stringB(){<br />return “don’t panic”;<br /> }<br />}<br />public classDeriv {<br />public overrideintA(){<br />return100;<br /> }<br />}<br />
  30. 30. public interface IFoo{<br />int Bar();<br />stringBaz(intarg);<br />}<br />
  31. 31. public abstractclassFoo{<br />public abstractint Bar();<br />public virtualstringBaz(intarg){<br />return “baz”;<br /> }<br />}<br />
  32. 32. IDisposable<br />public classMyClass : IDisposable {<br />File_myFile;<br />~MyClass(){<br /> _myFile.Close();<br /> }<br />public voidDispose(){<br /> _myFile.Close();<br />GC.SuppressFinalize(this);<br /> }<br />}<br />
  33. 33. using(var file = newMyFile()){<br />// ...<br />}<br />// oggetto distrutto<br />
  34. 34. delegate stringFiltro(string s);<br />FiltrofiltraSpazi = delegate(string s){<br />returns.Replace(“ ”, “”);<br />}<br />filtraSpazi(“ciao mondo”); // “ciaomondo”<br />
  35. 35. delegate stringFiltro(string s);<br />FiltrofiltraSpazi =<br />s => s.Replace(“ ”, “”);<br />
  36. 36. ThreadPool.QueueUserWorkItem(o => {<br />// operazione lunga<br />}, null);<br />
  37. 37. public staticclassStringExtensions {<br /> public staticstringGreet(thisstring s){<br />return“Ciao ” + s + “!”;<br /> }<br />}<br />
  38. 38.
  39. 39. DateTime<br />
  40. 40. public staticstringToIso8601(thisDateTimeval) {<br />returnval.ToString(@"yyyy-MM-ddTHH:mm:ss.ff",<br />CultureInfo.InvariantCulture);<br />}<br />
  41. 41.
  42. 42. newMyClass(“ciao”, 10);<br />newMyClass<int>(100);<br />
  43. 43. public classWidgetContainer {<br />object[] _array;<br />public voidAdd(Widgetinstance){ ... }<br />public WidgetGet(intindex){<br />return (Widget)_array[index];<br /> }<br />}<br />public classContainer<T> {<br />T[] _array;<br />public voidAdd(Tinstance){ ... }<br />public TGet(intindex){<br />return_array[index];<br /> }<br />}<br /> //Container<Widget><br />
  44. 44. Attribute<br />public MyAttribute : Attribute {<br />public intCount { get; set; }<br />}<br />[My(Count = 10)]<br />publicMyClass {<br />}<br />
  45. 45. varc = newMyClass();<br />varattrs = c.GetType()<br /> .GetCustomAttributes(typeof(MyAttribute), true);<br />varattr = (MyAttribute)attrs[0];<br />Console.WriteLine(attr.Count);<br />
  46. 46.
  47. 47. IEnumerable<T><br />IEnumerator<T> {<br /> T Current { get; }<br />boolMoveNext();<br />void Reset();<br />}<br />IEnumerable<T> {<br />IEnumerator<T> GetEnumerator();<br />}<br />
  48. 48. IEnumerable<T><br />int[] fibo = new { 0, 1, 1, 2, 3, 5, 8 };<br />foreach(var i infibo){<br />Console.Write(i);<br />}<br />// stampa: 0112358<br />
  49. 49. IList<T><br />IList<int> fibo = new { 0, 1, 1, 2, 3 };<br />fibo[2] = 2; //0, 1, 2, 2, 3<br />int c = fibo.Count; // c = 5<br />
  50. 50. System.Collections.Generic<br />List<T> : IList<T><br />Dictionary<K,T> : IDictionary<K,T><br />LinkedList<T> : ICollection<T><br />Stack<T> : IEnumerable<T><br />
  51. 51. System <br />System.Collections<br />System.Diagnostics<br />System.Globalization<br />System.IO <br />System.Net<br />System.Reflection<br />System.Runtime<br />System.Security<br />System.Text<br />System.Threading<br />
  52. 52. System.Linq<br />(System.Core.dll)<br />
  53. 53. varnums = from n inEnumerable.Range(0, 100)<br />letsquare = n * n<br />wheresquare >= 49<br />select n;<br />// 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ...<br />
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×