Friday, December 20, 2013

Do You Aware of Smart way Of Class Object Initialization

Class Object Initialization:

Friends Of course we do coding to get the result,but the thing is that how fast our code respond to achieve the task.
That's what industry,client look for,
There are several little & small things can be done to achieve or improve the performance,in which I would share you the way in which we should initialize object of class,this way of technique would improve your code performance,even you can find.Its because it do 1 time assignment of all objects to class.

I have a class called BatchSummaryDetails  to which I am assigning parameters

Suggested way:

 

     BatchSummaryDetails objBatchSummaryDetails = new BatchSummaryDetails()
                {
                    BatchType = "NameAny",
                    BatchTotalCount = totalCount,
                    BatchSuccessCount = Convert.ToString(successCnt),
                    BatchFailedCount = Convert.ToString(failedCnt),
                    BatchStartRecordNumber = startRecordNo,
                    BatchEndRecordNumber = endRecordNo,
                    BatchStartTime = batchStartTime,
                    BatchEndTime = DateTime.Now.ToString(),
                };

Routine Way:

 

   BatchSummaryDetails objBatchSummaryDetails = new BatchSummaryDetails();
                objBatchSummaryDetails.BatchType = "
NameAny";
                objBatchSummaryDetails.BatchTotalCount =
totalCount, 
                objBatchSummaryDetails.BatchSuccessCount = Convert.ToString(successCnt);
                objBatchSummaryDetails.BatchFailedCount = Convert.ToString(failedCnt);
                objBatchSummaryDetails.BatchStartRecordNumber = startRecordNo;
                objBatchSummaryDetails.BatchEndRecordNumber = endRecordNo;
                objBatchSummaryDetails.BatchStartTime = batchStartTime;
                objBatchSummaryDetails.BatchEndTime = DateTime.Now.ToString(); 



There are many tips I wanted to share i.a will share in coming posts which benefits a lot to improve your code performance.

No comments: