• Home
  • About
  • BestBloggingIdeas
  • DotNetLearningSource
  • FORUM
  • Joblinks
  • Latest News
  • Policy
  • POSTS
  • SimplySqlServer.Com && SimplyAspDotNet.Com
  • Sitemap

Join Ours Forum

Asp.Net,C#,Ajax,Sql server,silverlight,Javascript codes exambles articles,Programming exambles

RSS Feed
  • Bounty Huge Roll [Amazon Frustration-Free Packaging]
  • XML Introduction to XML VHS Video Training, 1 hr., 32 minutes.
  • The Basic Overview of Windows Mobile Development Asp.Net C#
  • Overview of Sql server extended properties Asp.Net C#
  • How to Use Sql Server Extended properties using visual studio Asp.Net C#
  • Adobe Dreamweaver Templates Accelerate Web Development
  • Top Tips for Web Design Projects
  • How to Achieve a Good Web Design Structure
  • To Use Or Not To Use Website Templates
  • Five Tips to a Successful Website
  • Top 10 Articles,


    Silverlight Datagrid Select Update Delete Insert Asp.Net C#

    Differences Similarities Benefits Between Typed Datasets and Untyped Datasets asp.net c#

    Linq to Sql Introduction Entities Ado.Net C# SqlClasses Attributes Linq Mapping

    Linq Programming/How Linq Works?/Linq Implementation In Asp.Net C# Ado.Net

    Performing Developing Using Investigating Asp.Net 2.0 Ajax Application Development Asp.Net C#

    Hosting/Install Wcf Services in a Windows Service Asp.Net C#

    Connecting Silverlight to Wcf Asp.Net C#

    Silverlight Data Grid Data Binding WCF Asp.Net C#

    Invoking/Accessing/Calling WCF Service Without Adding/Creating Proxy/Reference Asp.Net C#

    Performing Doing Creating Insert Update Delete sql data Using Linq Database Asp.Net C#

    What’s new in C# 4.0?

    Posted by on January 26, 2010 Leave a comment (0) Go to comments

    Introduction:
    Article discusses about some important features in c# 4.0.

    Main:

    Some Important features are,

    1. Dynamically typed objects
    2. Named and Optional function parameters
    3. Covariance and Contravariance

    Asp.Net 4.0 architecture ,(Downloaded from microsoft website)
    c40

    Dynamically Types Objects
    Today, in C# we may have the code to get the instance of class Calculator and then invoke the Add() method on that instance to return an integer.

    Calculator calc = GetCalculatorInstance();
    int sum = calc.Add(10, 20);

    Here all the objects are statically typed i.e. the type of the object is known at compile time. Now, let’s take an exmaple where the Calculator class resides in an assembly and we want to invoke the Add() method dynamically through C#. When the phrase “dynamically invoke method” comes, we immediately think of Reflection. Yes, you are correct, we will use reflection to invoke the Add() method as shown below:

    object calc = GetCalculatorInstance();
    Type type = calc.GetType();
    object result = type.InvokeMember("Add",
    BindingFlags.InvokeMethod, null,
    new object[] { 10, 20 });
    int sum = Convert.ToInt32(result);

    So far so good. Now what if you don’t want to play with reflection?
    Yes, you can do so in C# 4.0. Making the use of “statically typed dynamic object” you can achieve the same output as that of reflection. Let’s look at the code first, which will make our understanding more clear:

    dynamic calc = GetCalculatorInstance();
    int result = calc.Add(10, 20);

    In the above example we are declaring a variable, calc, whose static type is dynamic. Yes, you read that correctly, we have statically typed our object to be dynamic. We’ll then be using dynamic method invocation to call the Add() method and then dynamic conversion to convert the result of the dynamic invocation to a statically typed integer.

    I would still encourage you to use static types wherever possible, since they are the best for performance reason.

    Named and Optional function parameters
    Remember C++’s default values for function parameters that made the parameter in question optional? In C# 4.0 you will be able to do that. In previous version of the language to achieve this type of behavior we use to create overloaded methods with varying parameters. By doing this, number of methods would increase keeping the business logic almost same.

    Let’s assume that we have the following OpenTextFile method along with three overloads of the method with different signatures. The overloads of the primary method will call the primary method with default values for the arguments expected.

    4 arguments (Primary method)
    public StreamReader OpenTextFile(
    string path,
    Encoding encoding,
    bool detectEncoding,
    int bufferSize) { }

    3 arguments (Overloaded method)
    public StreamReader OpenTextFile(
    string path,
    Encoding encoding,
    bool detectEncoding) { }

    2 arguments (Overloaded method)
    public StreamReader OpenTextFile(
    string path,
    Encoding encoding) { }

    1 argument (Overloaded method)
    public StreamReader OpenTextFile(string path) { }

    In C# 4.0 the primary method can be refactored to use optional parameters as shown below:

    Single primary method accepting default values
    public StreamReader OpenTextFile(
    string path,
    Encoding encoding = null,
    bool detectEncoding = false,
    int bufferSize = 1024) { }

    It is now possible to call the OpenTextFile method omitting one or more of the optional parameters.

    OpenTextFile(“foo.txt”, Encoding.UTF8);

    It is also possible to provide named parameters and as such the OpenTextFile method can be called omitting one or more of the optional parameters while also specifying another parameter by name.

    OpenTextFile(“foo.txt”, Encoding.UTF8, bufferSize: 4098);

    Please note that named arguments must be provided last although when provided they can be provided in any order.

    Covariance and Contravariance
    An operator between types is said to be covariant if it orders these types from more specific to more general ones. Similarly an operator between types is said to be contravariant if it orders them in the reversed order. Whenever neither of these conditions is met, an operator is said to be invariant.

    Conclusion:
    Hope this helps,
    Happy Coding.

    ASP.NET
    ← Custom Div Scrollbar
    Datagrid Paging without Page Referesh →

    Learn Easily Using Video Tutorials


    How to choose the right Java IDE – explained Eclipse NetBeans BlueJ

    Developing/Creating/Performing/Configuring Java Applications Using Eclipse IDE

    Step By Step Guide for Download/Install Configure Eclipse IDE for Java

    Editing data with the GridView control Asp.Net C#

    Registering/Configuring Web Controls globally in web.config file asp.net c#

    Registering/Configuring Web Controls globally in web.config file asp.net c#

    Best way to prepare asp.net Interview - Success Stories

    Download Important Questions and PPT's:

    Sql Server Important Questions Online free download

    Dotnet Important Questions Online free download

    Exploring Linq to Sql Process Flow

    Learn how to perform silverlight programming

    Learn OOPs concepts in better and well manner

    Learn Ajax in better and well manner

    Leave a Reply Cancel reply

    Your email address will not be published. Required fields are marked *

    *

    *


    You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

    Enter your email address:

    Delivered by FeedBurner

    • Recent Posts

      • Bounty Huge Roll [Amazon Frustration-Free Packaging]
      • XML Introduction to XML VHS Video Training, 1 hr., 32 minutes.
      • The Basic Overview of Windows Mobile Development Asp.Net C#
      • Overview of Sql server extended properties Asp.Net C#
      • How to Use Sql Server Extended properties using visual studio Asp.Net C#
    • Search by Tags!

      Application AspNet Basic between Black Bluetooth Build Business Collection Consultants Design Development Downloading effective Excel Experts Generics Implement Installing Interview Logic Management Microsoft Minutes Object Outlook Professional Programmer Programming Project Projects Questions Ready Select Server Services Silverlight Source Strings Studio Through using Visual Website Wordpress
    • Archives

      • August 2011
      • June 2011
      • May 2011
      • April 2011
      • March 2011
      • February 2011
      • December 2010
      • November 2010
      • October 2010
      • September 2010
      • August 2010
      • July 2010
      • June 2010
      • May 2010
      • April 2010
      • March 2010
      • February 2010
      • January 2010
      • December 2009
      • November 2009
      • October 2009
      • September 2009

    Copyright © 2012 NetProgrammingHelp.com

    Δ Top