Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

Saturday, January 7, 2012

What's New in the .NET Framework 4.5 Developer Preview

This topic contains information about key features and improvements in the .NET Framework 4.5 Developer Preview. This topic does not provide comprehensive information and is subject to change.

New features and improvements are described as per bellow.

.NET for Metro style apps

Metro style apps are designed for specific form factors and leverage the power of the Windows operating system. A subset of the .NET Framework is available for building Metro style apps for Windows using C# or Visual Basic. This subset is called .NET APIs for Metro style apps. For more information about this subset.

Core New Features and Improvements

The following features and improvements were added to the common language runtime and to .NET Framework classes:
  • Ability to limit how long the regular expression engine will attempt to resolve a regular expression before it times out.
  • Ability to define the culture for an application domain.
  • Console support for Unicode (UTF-16) encoding.
  • Support for versioning of cultural string ordering and comparison data.
  • Better performance when retrieving resources.
  • Zip compression improvements to reduce the size of a compressed file.
  • Ability to customize a reflection context to override default reflection behavior through the CustomReflectionContext class.

Wednesday, January 4, 2012

In WPF getting error -"specified element is already the logical child of another element. disconnect it first."


→ I have found this error at the time of using datagrid. I have one condition to set visibility of the particular datagrid column.

→ I have used the following ColumnTemplate in the Grid.

  
→ Here, I was using Directly writing Content in the Header , so after set visibility Collapsed to Visible or vice versa for the particular colums, I was getting this error.

→ I have found the solution that , define the Template for the header instead of direct content as below. The Problem has been resolved by this.


Friday, November 11, 2011

What is new in Dot .Net 4.5 Framework Poster

Jouni Heikniemi, CEO and consultant in a four-person consultancy had create nice poster for new features of dot .net framework 4.5.

What's new in Dot .Net Framework

Saturday, July 16, 2011

C# 2.0 - Null Coalesce Operator

Null coalesce operator (??) was a very nice feature of C# 2.0. Null coalesce converts nullable type to non-nullable type. The ?? operator uses to define a default value for nullable type. For that in previous version of C#, we have to right like as bellow.

long lngMarks;
long lngAvg = (lngMarks == null ? 0 : lngMarks) / 6;

In above case, we use ternary operator(?) for check, value is null or not. Now it is more easy with Null Coalesce operator (??). We can use the Null - Coalesce Operator (??) as a shortcut for that expression, as shown here:

long lngMarks ;
long lngAvg = (lngMarks??0) /6;


Null coalesce operator(??) is a very small but very useful feature of C# 2.0.

Friday, July 15, 2011

Validation Class For String

Extension method is introduced by Microsoft in .Net 3.5. With help of extension method, developer can extend any class without change in original source code. Extension methods are static methods that can appear to be part of a class without actually being in the source code for the class. So extension method is one of the richest feature of .net 3.5.

Here I create class for string validation which extends string class. With help of bellow class we can validate some regular string validation like email, password , numeric etc. It provide facility to validate your own custom regular expression.

Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

Tuesday, July 12, 2011

C# : Tupel


Array can combine objects which have same type, but some time we need to combine objects which have different types. For that in Framework 4.0, Microsoft introduces new feature Tupel. Tuple provides facility to combine of different type of object in one object. Tupel is derived from programing language such as  F# or like Haskell in Python.  With .NET 4 , Tupel is available for all .NET languages.

Example
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            //get age from passed birthdate
           Tuple<int,int,int> age = calculateAge(new DateTime(1982,4,4));
            //Tuple value can access with age.Item1.........
           Console.WriteLine("Age {0} years, {1} months, {2} days", age.Item1, age.Item2, age.Item3);
           Console.ReadKey();
        }

Sunday, June 26, 2011

Extension method for IComparable

.net

Extension method for IComparable

C# 3.0 gives great feature of extension method. I am also very much interested for Extension method.  Today, My friend Divyang posts very useful topic "Extension Meathod for IComparable".  I would like to share you something interesting way to use that extension method. This time it's extending IComparable. The API signature for IComparable<T> has been around since the birth of  C language . If the left is less than the right, return something less than 0, if left is greater than right, return something greater than 0, and if they are equivalent, return 0. Well, its readability leaves a bit to be desired.
So Here we have set of extension methods for any type T that implements IComparable:

GUIDs (Globally Unique Identifiers) in .NET

.net

What is GUID ?

A GUID is a 128-bit integer that can be used to uniquely identify something. You may store as primary key in your database. A common approach is to create a auto incrementing integer, another way would be to create a GUID for your field. 
GUIDs can be generated in a number of ways; most often a hash of several things that might be unique at any given point in time like the IP address plus the clock date/time etc are used to generate Unique Ids. Each system may have slightly different algorithm to generate the Unique Id.

Thursday, June 23, 2011

Techdays 2011 : Expression Blend for Silverlight Developers

Every year Microsoft conducts Techdays specially for developer community. I found useful video of Techdays which was conducted at UK on "Expression Blend for Silverlight Developers".
The session is split into:
  • Workflow
  • Quick fire tips on Blend
  • Building an app

Saturday, June 18, 2011

As Operator in C#

The as operator is used to perform certain types of conversions between compatible reference types. "As" Operator is also known as a safe cast. What is does is it attempts to cast from one type to another and if the cast fails it returns null instead of throwing an InvalidCastException.
As-casting is equivalent to the following expression except that expression is evaluated only one time.
expression is type ? (type)expression : (type)null