Revealing C# 5

18
Revealing C# 5 By- Praveen Kumar Prajapati Blog: praveenprajapati.wordpress.com

description

New Features in C# 5

Transcript of Revealing C# 5

Page 1: Revealing C# 5

Revealing C# 5

By- Praveen Kumar PrajapatiBlog: praveenprajapati.wordpress.com

Page 2: Revealing C# 5

AgendaBackgroundNew Features in C# 5Breaking ChangesAsynchronous ProgrammingCaller Info AttributesWindows Runtime Support (Metro Style apps)The Road Ahead

Page 3: Revealing C# 5

BackgroundVersion

Theme Year .NET Visual Studio

C # 1.0 Managed Code Jan 2002 1.0 VS .NET 2002

C # 2.0 Generics Nov 2005 2.0 VS 2005

C # 3.0 Language Integrated Query

Nov 2007 3.5 VS 2008

C # 4.0 Dynamic Apr 2010 4.0 VS 2010

C # 5.0 Asynchrony and Windows Runtime

Feb 2012 4.5 VS 2011

Page 4: Revealing C# 5

New Features in C# 5 Breaking Changes

Lambda expressionsLINQ expressionsNamed arguments

Asynchronous ProgrammingCaller Info AttributesWindows Runtime Support

Page 5: Revealing C# 5

Breaking ChangesLambda expressions: Use of iteration variable of a

foreach statement in a lambda expression that’s contained in the body of the loop

LINQ expressions: Use of iteration variable of a foreach statement in a LINQ expression that’s contained in the body of the loop

Named arguments: Side effects from named and positional arguments in a method call now occur in the correct order

Page 6: Revealing C# 5

Breaking ChangesDemo :

Lambda expressionsLINQ expressionsNamed arguments

Page 7: Revealing C# 5

Asynchronous ProgrammingNew Keyword introduces:

async await

Rules and recommendations for use of those keywords

Page 8: Revealing C# 5

Asynchronous Programming

public Task<XElement> GetXmlAsync(string url) { var tcs = new TaskCompletionSource<XElement>(); var client = new HttpClient(); client.GetAsync(url).ContinueWith(task => { var response = task.Result; var text = response.Content.ReadAsString(); tcs.SetResult(XElement.Parse(text)); }); return tcs.Task;}

public async Task<XElement> GetXmlAsync(string url) { var client = new HttpClient(); var response = await client.GetAsync(url); var text = response.Content.ReadAsString(); return XElement.Parse(text);}

Page 9: Revealing C# 5

Asynchronous ProgrammingDemo: Use of async and awaitHow it reduces efforts and make code better

Page 10: Revealing C# 5

Caller Info AttributesMore easily obtain information about the caller of

a method. By using Caller Info attributes, you can identify the file path of the source code, the line number in the source code, and the member name of the caller.

Demo: The use of Caller info attributesHow it reduces efforts and make code better

Page 11: Revealing C# 5

Windows Runtime SupportWindows Runtime: WinRT, is Microsoft's new programming

model that makes the backbone of the new Metro-style apps (also known as Immersive) in Windows 8 operating system

.NET APIs for Metro style apps provides a subset of managed types that you can use to create Metro style apps. This subset of managed types is called the .NET APIs for Metro style apps.

Deep integration with the Windows Runtime - a C# project can compiled into a WinMD file and then referenced from a HTML/JavaScript project.

Page 12: Revealing C# 5

What is Metro StyleMetro is the whole design language behind Windows

Phone, and is a big part of the future of Microsoft

Using clean, crisp, clear information to get information across as quickly and accurately as possible

Windows Metro style apps are designed for specific form factors and leverage the power of the Windows operating system.

Page 13: Revealing C# 5

Windows Metro style apps Metro style apps are immersive and chromeless, filling the entire

screen so there are no distractions.

Metro style apps work together, making it easy to search, share, and send content between them.

Metro style apps are tailored to your users' needs, to specific devices, to touch interaction and hardware events, and to the new Windows user experience in Windows 8 Consumer Preview.

Page 14: Revealing C# 5

Metro style design principlesMetro style design has a set of five guiding principles to help you make the best choices when designing your app. These principles are the foundation for building great Metro style apps.

Show pride in craftsmanshipBe fast and fluidBe authentically digitalDo more with lessWin as one

Page 15: Revealing C# 5

What is excludedThe subset of managed types and members was designed with a clear focus on Metro style app development. As a result, it omits the following:

Types and members that are not applicable to developing Metro style apps (such as console and ASP.NET types).

Obsolete and legacy types.Types that overlap with Windows Runtime types.Types and members that wrap operating system functionality (such

as System.Diagnostics.EventLog and performance counters).Members that cause confusion (such as the Close method on I/O

types).

Page 16: Revealing C# 5

Windows Runtime SupportDemo: Window Runtime support

Page 17: Revealing C# 5

The Road AheadCompiler as a serviceThe Roslyn ProjectCTP of Visual Studio Roslyn in mid October 2011C# interactive window“Paste as VB” and “Paste as C#”

Page 18: Revealing C# 5

Thanks to You AllLet us grow together

Keep in touch:Blog: praveenprajapati.wordpress.com