C# 3.0 : Automatic Properties

February 24, 2008

Hello ,

Being a C# programmer , you’ve used to leverage propcode snippet to create a property . C# 3.0 provides you with a nice feature called “Automatic Properties” which enables you to avoid having to declare private accessor field for properties and write get/set logic , this will make your code more concise and legible . However , you can still create regular properties and change get/set logic.

This is a property created by C# 2.0 :

        private string propertyName;
        public string PropertyName
        {
            get { return propertyName; }
            set { age= propertyName; }
        }

And this one is re-writed using C# 3.0 :

public string PropertyName { get; set; }

Implementing this feature , the compiler automatically creates the get/set logics . If you need to make the above property readonly , add private keyword before set accessor :

public string PropertyName { get; private set; }

Advertisements

How to Load CSV File Into SQL Server Table/View

February 14, 2008

Hello ,

T-SQL ‘Bulk Insert’ statement lets you load CSV or any other user-specified file formats into table/view .  In a CSV file , each field is seperated by a Comma and each line represents a record. Now , open notepad and create a CSV file named ‘test.csv’ with the following content :

1,FirstName1,LastName1,20
2,FirstName2,LastName2,25
3,FirstName3,LastName3,30

 

The following procedure demonstrates loaing the CSV file into a temporary table :

Create Procedure dbo.LoadCSVFile
AS
Begin
Create Table #CSVTest( ID INT , FN Nvarchar(50) , LN Nvarchar(50) , Age INT )
BULK INSERT #CSVTest FROM 'c:\test.csv' WITH
(
FieldTerminator = ',' ,
RowTerminator = '\n'
)
SELECT ID,FN,LN,Age FROM #CSVTest
End

Executing the procedure results in :

result1.jpg


ANTS Profiler – .Net Code & Memory Profiler

February 7, 2008

Hello ,

RedGate ANTS Profiler is a great tool which enables you to identify bottlenecks in your code and optimize memory usage , It also profiles how long each line of code takes to be executed(line-level timing) and reports the slowest lines of code and procedures. In addition , It Integrates into Visual Studio with context sensitivity.

ANTS Profiler profiles Windows Applications , ASP.Net Web Applications , COM+ Applications and Windows Services which are written under .Net Framework 1.1 , 2.0, and 3.0.

Download 14-day free trial