Blog Stats
  • Posts - 631
  • Articles - 2
  • Comments - 137
  • Trackbacks - 25

 

CSharp

There are 5 entries for the tag CSharp

L'operatore ?? (2)

L'altro giorno parlavo, in questo post, dell'operatore ?? ma, lo ammetto, non mi sono spinto fino all'IL per capirne le differenze con l'operatore ?.A farlo ci ha pensato qualcun'altro:    One thing that I do want to point about this technique is that it is a bit more (slightly) than syntactic sugar - as it actually generates different IL than the same task implemented with the ternary operator.  For example, here is some typical ternary-based code... Leggi il resto alla fonte: Need a New Title : How Did I Miss This? Tags: .Net CSharp

Properties vs public fields redux...

Di una cosa simile, ne discutevo tempo fa con un paio di amici.  L'argomento citato in questo post è leggermente diverso ma il concetto è chiaro: evitare di esporre l'accesso diretto ai campi (pubblici) di un oggetto, ma incapsularlo un una proprietà. Il motivo lo spiega Eric Gunnerson in questo post (da cui cito): The reason that the library design guidelines suggest you write a property here is that it is important that libraries be easily versioned. If you put a property in there ahead of time, you can change the property implementation without requiring users to recompile their code. Sebbene più avanti lo stesso Eric dice: But, if the...

Properties vs public fields redux...

Di una cosa simile, ne discutevo tempo fa con un paio di amici.  L'argomento citato in questo post è leggermente diverso ma il concetto è chiaro: evitare di esporre l'accesso diretto ai campi (pubblici) di un oggetto, ma incapsularlo un una proprietà. Il motivo lo spiega Eric Gunnerson in questo post (da cui cito): The reason that the library design guidelines suggest you write a property here is that it is important that libraries be easily versioned. If you put a property in there ahead of time, you can change the property implementation without requiring users to recompile their code. Sebbene più avanti lo stesso Eric dice: But, if the...

GetTempFileName e GetRandomFileName

Decisamente molto utili in applicazioni Windows Forms: GetTempFileName: http://msdn2.microsoft.com/it-it/library/system.io.path.gettempfilename(VS.80).aspx GetRandomFileName: http://msdn2.microsoft.com/it-it/library/system.io.path.getrandomfilename%20(VS.80).aspx Tags: .Net CSharp Windows Forms

L'operatore ?? (C#)

Non l'ho visto utilizzare spesso e, lo ammetto, anche io ogni tanto me ne dimentico (per fortuna che c'è Resharper che me lo ricorda ). Si tratta dell'operatore ?? introdotto con il .NET Framework 2.0. Lo scopo è decisamente semplice: restituire un valore di dafault se il tipo è nullo, altrimenti restituire il valore corretto. Il tutto in forma molto compatta. In sostanza, anzichè scrivere un if o utilizzare l'operatore condizionale ? (in caso di valutazione dei null) in questo modo: 1: int? x = 0; 2: int y = (x == null) ? -1 : x; possiamo scrivere più semlicemente: ...

 

 

Copyright © Mighell |  Theme by Mighell.