Showing posts with label Visual Studio New Features. Show all posts
Showing posts with label Visual Studio New Features. Show all posts

Monday, June 22, 2009

C# 4.0 -Optional Parameters

I was really excited, when i have seen upcoming feature in c# 4.0, After come across some article, This feature will be very useful.


Optional Parameters

Let’s say I have a class Employee and I provide few overloads of the constructor to enable making certain parameters as optional as follows:

Older Method

public class Employee
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Qualification { get; set; }
public string MiddleName { get; set; }

public Employee(string firstName, string lastName)
{
FirstName= firstName;
LastName= lastName;
Qualification= "N/A";
MiddleName= string.Empty;
}
public Employee(string firstName, string lastName, string qualification)
{
FirstName= firstName;
LastName= lastName;
Qualification= qualification;
MiddleName= string.Empty;

}
public Employee(string firstName, string lastName, string qualification,
string middleName)
{
FirstName= firstName;
LastName= lastName;
Qualification= qualification;
MiddleName= middleName
}
}

Newer Method

public Employee(string firstName, string lastName,
string qualification = "N/A", string middleName = "")
{
FirstName= firstName;
LastName= lastName;
Qualification= qualification;
MiddleName = middleName;
}

Monday, April 13, 2009

Showing Intelligence for JavaScript methods in different Files.


Showing Intelligence for JavaScript methods in different Files.
I have created Jscript1.js with following methods with out definition.




I am referring the jscript1.js file in to script2.js using Reference Attribute. After adding the reference am getting intelligence for the jscript1.js file methods.

Thursday, January 8, 2009

Typed Dataset Using Asp.net 3.5

Typed Dataset Using Asp.net 3.5

Before starting we will remember in Dotnet frame work 2.0. In this it will create only xsd and class file for that. But it will not create Adapters for retrieving dataset. We should use Sqldataadapter for getting the data. But in Asp.net 3.5 frame work it will create data adapter for that xsd. So we can get the typed dataset via adapter instead of getting from Sqldataadapter. See the step by step explanations with examples.


Step 1:

Create one employee database with table name called “contact” which has created for you. Open that database in server explorer of visual studio 2008. See picture A






Picture A

Step 2:

Create Contact.xsd file through add file option in project file. See picture B


Picture B

Step 3:

Drag and drop contact table in to the contact.xsd screen. After waiting few seconds it will create Contact.xsd file automatically. Now you can see in picture C


Picture C


Step 4

Writing few lines of code assigning this typed data values in gridview. See picture as well as the code to retrieve the typed dataset. Create one aspx page with gridview control. I am going to write the code in page load event for that page.

Example:

protected void Page_Load(object sender, EventArgs e)
{
ContactTableAdapters.ContactTableAdapter Dataadapt = new Dotnetspider.ContactTableAdapters.ContactTableAdapter();
grdlist.DataSource = Dataadapt.GetData();
grdlist.DataBind();
}

Note: ContactTableAdapter class will create automatically. This is the one main difference between frame work 2.0 and framework 3.5. But in 2.0 frame work will not create.

Happy Coding

By

Bala

Note:Images will update soon. Sorry for the inconvenience.

Monday, January 5, 2009

Using Filter Expressions with an SQL Data Source in ASP.NET VB 2008

In Visual Studio 2008, we can filter the dataset in c# with out using sqlquery.

If you use sqldatasource in your project. we can filter the dataset in c# coding itself.

Example1

If (Session("FiltExp") <> Nothing) Then
SqlDataSource1.FilterExpression = Session("FiltExp").ToString()
End If

Example2

SqlDataSource1.FilterExpression = "city='" & DropDownList1.SelectedValue & "'"

Example3

SqlDataSource1.FilterExpression = "BirthDate > #" + dt + "#"
Session("FiltExp") = "BirthDate > #" + dt + "#"

Hidden Features in C#

1) Using @ for variable that are keyword.

var @object = new object();
var @string = "";
var @if = IpsoFacto();

2) Aliased Generics.

using ASimpleName = Dictionary<string, Dictionary<string, List<string>>>;


Allows you to ASimpleName,instead of

Dictionary<string, Dictionary<string, List<string>>>;

Use it when you would use the same generic big long complex thing in a lot of places.

Tuesday, October 14, 2008

Visual studio 2008 has a new style builder dialog

Visual studio 2008 has a new style builder dialog. For creating new style sheet, viewing the style sheet with design.Please follow the below steps to create the style sheet throgh VS tools.
step1:

step2:


step3: