Ohad's Blog

Lets talk about .net !

Mirror at:
blogs.microsoft.co.il

News

         Ohad Israeli's Facebook profile

Grab this badge here!

C# Code Snippts

Favorite Blogs

Israeli .Net Bloggers

Silverlight 4 Training @ CH9

Channel 9 just published a Silverlight 4 Training which includes hands-on-labs, a video and a whitepaper designed to help you learn about the new features in Silverlight 4 !

The training is focused on three major areas:

Enabling Business Application Development

Empowering Richer Experiences

Moving Beyond the Browser

Silverlight 4 now includes cool features like Printing, WebCam and Microphone support, custom right-click, rich text, HTML support and access to local files with trusted applications.

Check it out over here

Microsoft PDC 09 – The Videos

PDC videos are starting to show up… keep an eye on http://microsoftpdc.com/Videos

The quality of the videos type WMVHIGH is very good although the files might consume large amount of storage for ones who will try to download them all.

Let the HOME PDC BEGIN !

Any chance to send home PDC attendees also a new tablet ?

image

Posted: Nov 19 2009, 08:00 AM by Ohad Israeli | with no comments
Filed under: , , ,
Ray speaks live from PDC 09 Conf @ LA

image

Cool ! – live streaming !

http://microsoftpdc.com/

Posted: Nov 17 2009, 06:45 PM by Ohad Israeli | with no comments
Filed under: , , ,
Free training on Visual Studio 2010 and C# 4.0

Did you know that you can train yourself for what’s new in Visual Studio 2010 and C# 4.0 (also VB) ?

The Microsoft Visual Studio 2010 and .NET Framework 4 Training Kit - October Preview is available for more than a week now and it includes lots of slide decks, demos and labs covering the following topics:

  • Whats New In the .NET Framework 4
  • Whats New In Visual Studio 2010
    • Video: Downloading And Installing Visual Studio 2010 Beta 2
    • Demo: Hello Visual Studio 2010
  • Common Language Runtime
    • Demo: System.Threading.Barrier Demo
    • Demo: System.Threading.CountdownEvent
  • Managed Languages
    • What's New In C# 4 and Visual Basic 10
    • Video: Fixing PIA Pains with Type Equivalence
    • Demo: Managed Languages 10-in-1
    • Lab: Introduction To F#
    • Lab: Visual Studio 2010: Office Programmability
    • Lab: Visual Studio 2010: Test Driven Development
  • ASP.NET 4
    • Introduction to ASP.NET MVC
    • Whats New In ASP.NET AJAX 4
    • Whats New In ASP.NET Web Forms 4
    • Web Deployment with Visual Studio 2010
    • Video: Simplifying Data-Driven Web Applications
    • Demo: AdventureWorks using AJAX
    • Demo: ASP.NET AJAX 10-in-1
    • Lab: ASP.NET AJAX
    • Lab: Building an Web Application
    • Lab: Enhancing a Web Application
    • Lab: Introduction to ASP.NET Web Forms 4.0
    • Lab: Web Development in Visual Studio 2010
  • Windows
    • What's New in Windows Presentation Foundation 4
    • Lab: Building a Data-Driven Master/Detail Business Form in WPF using Visual Studio 2010
    • Lab: Taskbar - MFC
    • Lab: Gestures - MFC
    • Lab: Multitouch - MFC
    • Lab: Ribbon – MFC
  • Windows Workflow
    • Workflow 4: A First Look
    • Video: Workflow Web Services
    • Lab: Introduction to Workflow 4.0
    • Lab: WCF Service Discovery using .NET Framework 4.0
  • Windows Communication Foundation
    • Lab: WCF Service Discovery using .NET Framework 4.0
  • Silverlight
    • Introduction to .NET RIA Services
  • Data Access
    • Whats New In Entity Framework 4
    • Whats New In ADONET Data Services 1.5
    • Introduction to Project "Velocity"
    • Video: Server-Driven Paging with ADO.NET Data Services
    • Demo: Project Velocity
    • Lab: Introduction to ADO.NET Data Services
    • Lab: Introduction To Project "Velocity"
  • Parallel Computing
    • Parallel Computing for Managed Developers
    • Demo: ContosoAutomotive Demo
    • Demo: BabyNames
    • Demo: Parallel.For Loop
    • Demo: Parallel LINQ (PLINQ)
    • Demo: System.Threading.Tasks
    • Lab: Parallel Extensions: Building Multicore Applications with .NET
  • Extensibility
    • Introduction to the Managed Extensibility Framework
    • Video: MEF Preview 7
    • Demo: Demos for "Intro to Mef" Presentation
    • Lab: Introduction To Managed Extensibility Framework
  • Application Lifecycle Management

Download the Visual Studio 2010 and .NET Framework 4 Training Kit - October Preview

Channel 9 also hosting lots of VS 2010 & .NET 4.0 Training classes

What’s new in Visual C# 4.0 ? – Part 3 - Dynamic ExpendoObject

This is the third post of what’s new in Visual Studio C# 4.0.

At the former posts we covered optional parameters, Named Parameters at this post we will cover C# Dynamics and ExpandoObject

dynamic & ExpendoObject

C# 1.0 introduced us to the managed world (based on Microsoft perception)

C# 2.0 brought us Genetic types.

C# 3.0 introduced us to new concept – LINQ

C# 4.0 highlight is all about Dynamic Types

Say for example that you have the need to create an object on the spot and use it in a local scope, without dynamic type you had to define a class and then create the object. you could do it at runtime using reflection emit, code dom etc…now its much simpler !

All you have to do it to create an object of the type dynamic and using a special builder called ExpandoObject you can now define your object on the fly and use it.

  1. class Program
  2.     {
  3.         static void Main(string[] args)
  4.         {
  5.             dynamic person = new ExpandoObject();
  6.             person.Firstname="ohad";
  7.             person.Lastname = "israeli";
  8.             Console.WriteLine(person.Firstname);
  9.             Console.WriteLine(person.Lastname);
  10.             Console.ReadLine();
  11.         }
  12.     }

You may say… wow this is cool.. well wait and see some more cool stuff..

Now lets add to this example and say that you would like to add a functionality to this object, what about adding person.Fullname in order to join the first and last name of the person and return it back.

  1. class Program
  2.     {
  3.         static void Main(string[] args)
  4.         {
  5.             dynamic person = new ExpandoObject();
  6.             person.Firstname="ohad";
  7.             person.Lastname = "israeli";
  8.             person.Fullname = new Func<string>(delegate() { return person.Firstname + " " + person.Lastname; });
  9.             Console.WriteLine(person.Firstname);
  10.             Console.WriteLine(person.Lastname);
  11.             Console.WriteLine(person.Fullname());
  12.             Console.ReadLine();
  13.         }
  14.     }

As you can see we can point the new object properties to lambda expressions such as Func<string> and define on the spot a function that will return the full name of the person.

Note that on line 12 you need to call the function and not use it as property – person.Fullname()

What will happen if you forget the () by the end of the function name ? (note the change on line 12)

  1. class Program
  2.     {
  3.         static void Main(string[] args)
  4.         {
  5.             dynamic person = new ExpandoObject();
  6.             person.Firstname="ohad";
  7.             person.Lastname = "israeli";
  8.             person.Fullname = new Func<string>(delegate() { return person.Firstname + " " + person.Lastname; });
  9.             Console.WriteLine(person.Firstname);
  10.             Console.WriteLine(person.Lastname);
  11.             Console.WriteLine(person.Fullname);
  12.             Console.ReadLine();
  13.         }
  14.     }

 

 

The result will be the lambda expression itself instead of the result of the lamba expression:

ohad
israeli
System.Func`1[System.String]

You can also add methods and not just functions using the Action expression: (note line 9)

  1. class Program
  2.     {
  3.         static void Main(string[] args)
  4.         {
  5.             dynamic person = new ExpandoObject();
  6.             person.Firstname="ohad";
  7.             person.Lastname = "israeli";
  8.             person.Fullname = new Func<string>(delegate() { return person.Firstname + " " + person.Lastname; });
  9.             person.CallOhad = new Action(() => { Console.WriteLine("Hi Ohad are you there ?"); });
  10.             Console.WriteLine(person.Firstname);
  11.             Console.WriteLine(person.Lastname);
  12.             Console.WriteLine(person.Fullname());
  13.             
  14.             person.CallOhad();
  15.             Console.ReadLine();
  16.         }
  17.     }

In conclusion dynamic types are cool but and there is a big but !

They are hard to debug and some of their functionality is only being tested at runtime this is why it is very important that whenever you use dynamic types test, test, and do some more testing using unit test of your code.

If you follow the following code you will notice that each of the calls to the properties in lines 11,12,13 begins with a small letter instead of uppercase.  This code will compile without any errors but of course the code will fail at runtime as the properties / function names are all uppercase.

  1. class Program
  2.     {
  3.         static void Main(string[] args)
  4.         {
  5.             dynamic person = new ExpandoObject();
  6.             person.Firstname="ohad";
  7.             person.Lastname = "israeli";
  8.             person.Fullname = new Func<string>(delegate() { return person.Firstname + " " + person.Lastname; });
  9.             person.CallOhad = new Action(() => { Console.WriteLine("Hi Ohad are you there ?"); });
  10.             Console.WriteLine(person.firstname);
  11.             Console.WriteLine(person.lastname);
  12.             Console.WriteLine(person.fullname());
  13.             
  14.             person.CallOhad();
  15.             Console.ReadLine();
  16.         }
  17.     }
What's new in Visual C# 4.0 ? - Part 2 - Names Parameters

This is the second post of what’s new in Visual Studio C# 4.0.

At the former post we reviewed the feature of optional parameters at this post we will concentrate on Named Parameters.

Named Parameters

Lets assume you are writing the following procedure :

  1. public static void SaySomething(string name, string msg)
  2.         {
  3.             Console.WriteLine(string.Format("Hi {0} !\n{1}", name,msg));
  4.         }

When you want to call it from your code you are using something like:

Code Snippet
  1. static void Main(string[] args)
  2.         {
  3.             SaySomething("Ohad","What's up?");
  4.             Console.ReadLine();
  5.         }

What’s the problem ?

Although you will have intellisense while you are coding it for the reader of the code its unclear what is the first parameter and what is the second parameter.

This is where Named Parameters gets into the picture. Using named parameter the code becomes much more readable to one who haven’t wrote it.

Code Snippet
  1. class Program
  2.     {
  3.         static void Main(string[] args)
  4.         {
  5.             SaySomething(name: "Ohad", msg: "What's up?");
  6.             Console.ReadLine();
  7.         }
  8.         public static void SaySomething(string name, string msg)
  9.         {
  10.             Console.WriteLine(string.Format("Hi {0} !\n{1}", name,msg));
  11.         }
  12.     }

Named parameters are specially useful whenever you have multiple optional parameters of the same type. Without using named parameter how would the compiler know if the parameter which is being passed by line 5 is the name or the message.

Code Snippet
  1. class Program
  2.     {
  3.         static void Main(string[] args)
  4.         {
  5.             SaySomething(name: "Ohad");
  6.             Console.ReadLine();
  7.         }
  8.         public static void SaySomething(string name = "Tirza", string msg = "Hi There")
  9.         {
  10.             Console.WriteLine(string.Format("Hi {0} !\n{1}", name,msg));
  11.         }
  12.     }
What's new in Visual C# 4.0 ? - Part 1 - Optional parameters

This is the first blog from a series of blog post which I'm planning to do on whet’s new in Visual C# 4.0

Optional parameters

Optional parameters is a new feature in C# 4.0 which will let you set a default value for an argument of a method. In case that the collie of the method will omit the argument the default value will take its place.

So instead of writing the following code:

  1. class Program
  2.     {
  3.         static void Main(string[] args)
  4.         {
  5.             SaySomething();
  6.             SaySomething("Ohad");
  7.             Console.ReadLine();
  8.         }
  9.         public static void SaySomething()
  10.         {
  11.             Console.WriteLine("Hi !");
  12.         }
  13.         public static void SaySomething(string name)
  14.         {
  15.             Console.WriteLine(string.Format("Hi {0}!",name));
  16.         }
  17.     }

You will only have to write:

  1. class Program
  2.     {
  3.         static void Main(string[] args)
  4.         {
  5.             SaySomething();
  6.             SaySomething("Ohad");
  7.             Console.ReadLine();
  8.         }
  9.         public static void SaySomething(string name = "")
  10.         {
  11.             Console.WriteLine(string.Format("Hi {0}!",name));
  12.         }
  13.     }

 

 

The statement name = “” at line 11 does the trick of the optional parameter with passing and empty string as the optional parameter.

Note that some of the reader of this post my think that its better to use string.Empty instead of double quote “” as it normally do but :

Code Snippet
  1. class Program
  2.     {
  3.         static void Main(string[] args)
  4.         {
  5.             SaySomething();
  6.             SaySomething("Ohad");
  7.             Console.ReadLine();
  8.         }
  9.         public static void SaySomething(string name = string.Empty)
  10.         {
  11.             Console.WriteLine(string.Format("Hi {0}!",name));
  12.         }
  13.     }

using string,Empty will result with a compilation error:

“Default parameter value for 'name' must be a compile-time constant”

And as it string.Empty is not a literal.

Download Visual Studio 2010 Beta 2 (No need for MSDN)

As for today you can download Visual Studio 2010 Beta 2 even if you don’t have access to MSDN.

Just follow the links below and download your favorite version.

Visual Studio

Visual Studio Extensibility

.NET Framework

Team Foundation Server

Test Products

Express

Visual Studio 2010 Training Sources

Visual Studio 2010 & .NET Framework 4 Training Kit

clip_image002

The October preview of the Visual Studio 2010 & .NET Framework 4 Training Kit which has content that had been tested with Beta 2 is ready for download.

Download: Visual Studio 2010 and .NET Framework 4 Training Kit

Training Course on Channel 9

clip_image004

Channel 9 launches an online learning center that will play host to developer focused training courses created by developers for developers.  The videos and labs, with links to extensive training kits, will get you started on hands-on-learning with VS 2010 & .NET 4.0. 

Browse: Visual Studio 2010 and .NET Framework 4 Training Course

How to Download and Install Visual Studio 2010 Beta 2

clip_image006

In this episode of 10-4, Brian Keller takes us through downloading and installing Visual Studio 2010 Ultimate Beta 2 and Visual Studio 2010 Team Foundation Server Beta 2. This time-compressed video will take you through all of the key things you need to know to get up and running quickly with beta 2.

Watch: Brian’s 10-4 Episode on Channel9

Enable VS 2010 Multi Targeting also for VS2005 C++

One of the big new features for the C++ world in VS 2010 is "native multi-targeting".

This means that an MSBuild-based VC project can be built against any set of tools (compilers, linkers, headers, libs, etc).

VS 2010 ships with support for targeting either the 2010 toolchain or the 2008 toolchain. But the design allows you to target just about any version - and still load and work with it in the VS 2010 IDE.

Take the attached file that I’ve prepared and open it inside:

%PROGRAMFILES%\MSBuild\Microsoft.Cpp\v4.0\Platforms\Win32\PlatformToolsets\

And now you will now be able to target to v80 (vs2005) and not just to v90 (vs2008) or v100 (vs2010)

image

More Posts Next page »