Visualizzazione post con etichetta C#. Mostra tutti i post
Visualizzazione post con etichetta C#. Mostra tutti i post

sabato 19 gennaio 2013

Appunti di C#

Per rispondere in modo stringato ad eventi:
btnSubmit.Click += (sender, e) => MessageBox.Show("You clicked save!");

Per ogni elemento di un tipo enumerabile:
List elems = new List { "a", "b" };
elems.ForEach(el => Console.WriteLine(el));
elems.ForEach(el, Console.WriteLine);


Modifica elementi GUI cross thread:
private void SetupMainStepCount(int c)
{
   if (InvokeRequired)
      BeginInvoke(new Action(SetupMainStepCount), c);
   else
      totalProgress_.Maximum = c;
}

mercoledì 11 maggio 2011

VS 2008 C#: partial classes raggruppate

C# (e credo anche VB) permette di splittare il codice di una classe in diversi files (wow! quasi come il C++!) attraverso il costrutto delle partial classes.

Ad esempio supponiamo di creare un Form: l'IDE creerà per noi un file Form1.cs e un file Form1.Designer.cs (quest'ultima contenente il codice auto-generato dal designer).
Supponiamo ora di voler aggiungere alcuni controlli, e separare il codice della gestione degli eventi generati dai controlli per evitare di raggruppare in un unico file sorgente tutto il codice.
Creiamo quindi un file Form1.Eventi.cs, contenente tutto il codice relativo alla risposta agli eventi del Form.
L'editor di Visual Studio 2008 non è in grado di accorpare automaticamente il nuovo file come fa invece con il Form1.Designer.cs....

Per ottenere questo effetto, occorre editare a mano il file di progetto (quello con estensione .csproj nel caso di C#).

Alla sezione realtiva a Form1.Eventi.cs:


<Compile Include="Form1.Eventi.cs">
   <SubType>Form</SubType>
</Compile>


Va aggiunta una riga:


<Compile Include="Form1.Eventi.cs">
   <DependentUpon>Form1.cs</DependentUpon>
   <SubType>Form</SubType>
</Compile>


Con questa direttiva, ricaricando il progetto, l'IDE raggrupperà in un unico ramo dell'albero tutti componenti parziali di Form1

lunedì 17 marzo 2008

db4objects: un db engine object oriented

db4objects è un engine db object oriented con doppia licenza (alla MySQL) disponibile in versione open e in versione commerciale ed è in grado di integrarsi con Java e con la piattaforma .NET.
Sembra disporre di tutto ciò che serve (transazioni, query language avanzato, sistemi per il supporto al refactoring) per lo sviluppo di applicazioni orientate ai dati di nuova generazione.
Staremo a vedere.

venerdì 25 gennaio 2008

Null coalescing operator

Geniale, utile, elegante.

public static Singleton getInstance()
{
return theInstance ?? (theInstance = new Singleton());
}



Per il momento, disponibile in C# 2

sabato 17 febbraio 2007

.NET and svn

I've finally started my new job! I have to join the development of different projects in C#. There are 2 up to 7 developers for each project; until now, they used Visual Source Safe to handle all the projects, but now we have the need to export over the Internet the ability to work with centralized source. Also, from some locations we have the ability to access only the web via http or https (there are firewalls which we can't configure specifically). The solution was to use Subversion - thanks Simon, even if you'll hate me for using it with Microsoft ;) - in combination with Apache to set up a centralized service for source revision, control, and backup. All you need is:
and optionally:
Yesterday I've set up a beta environment, lets do some testing.
Keep tuned!

giovedì 18 gennaio 2007

.NET Part 2

Some more on .NET: I've started the “build your first web application” part, and I'm quite impressed: ISS behaves like a servlet container, and can handle both C# and VB code behind. And it's quite responsive, at least in a “single-user developing and testing” situation. It integrates quite easily with Ms SQL Server, but the most impressive thing (at least for me, as I've always developed web apps with Java and with tons of frameworks or library not supported by the IDE) is the capability of editing web pages WYSIWYG. And still... all this with the “Express” editions, which are free... Naturally all this works well rendered with MS Internet Explorer, and the question is: “Will it work with other browser/OSes?”. Well... try going on “msdn.microsoft.com” with firefox and linux... guess what: it works!

venerdì 29 dicembre 2006

C#: first impressions

I've started studying C# as I'll soon start a project in this language. It's similar to Java, so I'm not doing a giant effort; I like it, it's much better that VB, and Microsoft is offering a free (of charge, not free the GPL-way!!) development environment, for home and study purpose; I'll soon inquiry which are the limitations of this tool. But what I was thinking while reading some manuals is that Sun and Java are surely pointing in the right direction, if MS is going after, and C# is the “Microsoft's version of Java”; but now Java has a great advantage: it has been released under open source! And runs very well on a variety of platforms. But C# is somehow enhanced from J++, and it has some features borrowed from C++ (something I've actually missed a lot, programming in Java):
  • Delegates (from C++'s function pointers)
  • Stack based structures (in Java every object is heap based, while in C++ you have full freedom but you lack the garbage collector)
  • Properties (getter/setter)
What I'm not sure of its goodness is the lack of checked exception, which guarantees in Java a better software robustness; I'll see soon in real world projects if this will be penalizing. In the next days I will start studying the .NET library, and I will start using the IDE.