Galin Iliev's blog

Software Architecture & Development

C# 3.0 Partial Method Definitions

While I dug into Orcas March CTP Documentation I found another new C# feature (at least for me). It is called Partial Method Definitions and allows you to separate method definition and method implementation in partial classes.


partial void partial void onNameChanged();



partial void onNameChanged()


  //method body



As I have C++ background this sounds familiar to me and reminded me times when I had to declare methods in .h (header) files and put implementation in .c/.cpp files.

To be honest I am not able to find the advantages of this new feature but I suppose there will be more blog post soon that will discuss this.

As I emphasize above you can separate method definition from implementation only in partial classes. There are number of restrictions stated in Orcas documentation:

  • Partial method declarations must begin with the contextual keyword partial and the method must return void.
  • Partial methods can have ref but not out parameters.
  • Partial methods are implicitly private, and therefore they cannot be virtual.
  • Partial methods cannot be extern, because the presence of the body determines whether they are defining or implementing.
  • Partial methods can have static and unsafe modifiers.
  • Partial methods can be generic. Constraints are placed on the defining partial method declaration, and may optionally be repeated on the implementing one. Parameter and type parameter names do not have to be the same in the implementing declaration as in the defining one.
  • You can not make a delegate to a partial method.


C# 3.0 Auto-Implemented Properties

I have downloaded VS Orcas March CTP and I am playing with its features now.

I found one very cool feature called Auto-Implemented Properties. This will allow you to create private field and public property accessor with single C# 3.0 line like this:

public string FullName { get; set; }

instead like in c# 2.0:

private string fullName;


public string FullName


    get { return fullName; }

    set { fullName = value; }


And as with the others cool language sugars the compiler will do the rest :). Actually it doesn't look that good but still it works. For the single line property above I got the following code in Reflector:

public string FullName





        return this.<>k__AutomaticallyGeneratedPropertyField0;





        this.<>k__AutomaticallyGeneratedPropertyField0 = value;



Nice huh?

Of course this won't work if you have complex getters and setters but still will speed up code writing and leave more time for thinking :)

C# 3.0 and LINQ Tutorial

After speaking with my friend Marto I decided to write a tutorial about forthcoming features in new version of the very popular language C#.

As always there is a lack of development materials in Bulgarian so it is written in Bulgarian and there is no language barieer for bulgarian developers who wants to take a look behind the corner to new version of our favorite C#.

There is posibility to translate the whole tutorial in English (when it si finished) so this could be good starting point for all English speaking devs but this depends on the interest (and my availability).

I have posted first two parts (of total 13 so far): Introduction and Acknowledgment with LINQ and basic capabilities.

I hope I will be able to post next part very soon (projected within next two weeks) and I will announce it here.

In the meantime I will be very grateful for your feedback. Any comments, reccomendations and request for more detailed reviews are welcome. You can post them as comments on the blog or to my emails stated on here.

Thank you

LINQ projects in VS "Orcas"

Yesterday I installed VS "Orcas" January CTP on my machine in order to take deeper look at things that are comming.

I was a bit surprised I could not find VS LINQ project templates and compiler throws compile error on correct linq statement.

This was kind of strange - The VS version that introduces LINQ return compile error on correct LINQ statement ???!?!?!?

The problem was only in referenced  assemblies as this post says.

So to have LINQ syntax in your VS "Orcas" you have to:

  • Add reference to LINQ assemblies located in C:\WINDOWS\Microsoft.NET\Framework\v3.5.*. You can reference them all or only those you need (The important ones are System.Core.dll, System.Data.Entity.dll, System.Data.Linq.dll and System.Xml.Linq.dll
    The core is for the standard linq queries, where Data.Linq and Xml.Linq are what the old DLinq and XLinq were. )
  • Add using clauses at the top of source files.
    using System.Linq;
    using System.Data.DLinq;
    using System.Xml.Linq