rss
twitter
  •  

C# 3.0 New Features

| Posted in C# |

0

In this post, i will write about all the new features in C# 3.0, this features will help you more and more in your programming life, and class design.

this list of C# features which will be covered here,

1. Extension method

2. Lambda expression

1. Extension Method

  • extension method is new feature in C# 3.0, it is like static methods which we know in our object oriented background but with more main differences:
    • Extension methods must written in static class not like static method which can written in any class
    • To specify extension method, you need to write this keyword before the first argument in the method, static methods don’t have this keyword at declaration
    • at consumed, the argument with this keyword isn’t passed to the function
    • extension methods can be called only on instances, calling them on class will result in compilation errors, the class instances on which they are called are determined by the first argument in the declaration in other words the argument has this keyword
    • Note that extension methods can’t access private methods of extended type
    • Note that if you don’t have source code of type, and you don’t add new methods to type
    • Note that if you create extension methods that have the same signature methods inside the type you are extending, then the extension methods will never called.
    • extension methods can’t be used to override existing methods
    • concept of extension methods can’t be applied to fields, properties or events
    • if the class is sealed than there in no concept of extending its functionality, for this a new concept is introduced

But why you determine that you want to implement this new feature, let’s assume the following scenario you need to implement new method in Int class to get the power of the integer, as the traditional thinking you will design class which inheriting from the parent class Int and implement new method called Power but with C# 3.0 you have another option implement extension method  Power() on Int class, let’s try it with your hand

Be Higher Productive with Visual Studio 2010

| Posted in Microsoft Visual Studio |

0

use Extension Manager, Search in the Online Gallary for Power Productive tools and check the difference

Creating Map File for DataContext in LINQ to SQL

| Posted in Uncategorized |

0

Creating a mapping document manually is a time-consuming, error-prone activity. Visual Studio includes a command-line tool named SQLMetal.exe that can be used to generate the mapping file based on a database schema.

Simple Look @ Transaction in ADO.Net

| Posted in Uncategorized |

0

   // C#   
             DbTransaction tx;
             try 
             {
                 conn.Open();
                 tx = conn.BeginTransaction();
                 cmdDeleteOrders.ExecuteNonQuery();
                 cmdDeleteCustomer.ExecuteNonQuery();
                 tx.Commit();
                 conn.Close();
             }
             catch (Exception exception)
             {
                 if (tx != null)
                 {
                     tx.Rollback();
                 }
                 if (conn != null)
                 {
                     if (conn.State != ConnectionState.Closed)
                     {
                         conn.Close();
                     }
                 }
             }

The exception handling can be simplified if the previous code is refactored as shown in this next code. The using statement calls Dispose() on the transaction object. The Dispose method checks to see if there are any uncommitted changes. If there are, it rolls back the transaction

  
              // C#   
             conn.Open();
             using (DbTransaction tx = conn.BeginTransaction())
             {
                 cmdDeleteOrders.ExecuteNonQuery();
                 cmdDeleteCustomer.ExecuteNonQuery();
                 tx.Commit();
                 conn.Close();
             }

Multiple Active Result Set (MARS) @ADO.Net

| Posted in Uncategorized |

1

While my certification study i want to share this information with any one, On a standard connection—that is, one that doesn’t use MARS—it is possible to have only a single open result set at any moment during the lifetime of the connection. This means that should multiple operations be required, the connection must be closed and reopened each time, which can be an expensive process. (ADO.Net MCTS EBook)

but you need to do this by To use MARS, a simple modification to the connection string is required, namely, another name-value pair called MultipleActiveResultSets=true. Look at what happens with this setting enabled