Click here to Skip to main content
Click here to Skip to main content

Beauty of Partial Class!!!

, 21 Mar 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
Nicely use of partial class

 Say i have a Database table name Employee and has 4 columns like ID, Firstname, Lastname,Email etc. That is, there is no Fullname Column but we need to display it on the List Form. So what we usually do? We fetch all data; iterate over the list of data to make the Fullname String right? But there is another nice way to do that, if we get the property Fullname like Firstname or Lastname then it might help us a lot for further processing. What I did for that, I have an Employee class in my dbml file. So I have created a partial Class name Employee in which I have define a Property Fullname as read-only. So when we get the Object Employee we will get the property Fullname. Have a look on code please. 

public partial class Employee
{  
   public string FullName
   {
     get
     {  
        StringBuilder sb = new StringBuilder();
        sb.Append(this.Firstname);
        sb.Append(" ");
        sb.Append(this.Lastname);
        return sb.ToString();                                                  
     }
   }        
}

Very very easy stuff!!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Md. Rashim uddin
Software Developer (Senior) KAZ Software Limited.
Bangladesh Bangladesh
I am a true visionary as well as have always been passionate about learning. I always love to work with thought-provoking personnel to develop amazing, exciting and innovative ideas as part of an aggressive team that challenges my ingenious ideas, creativeness and extensive experience.
 
My Blog: http://rashimuddin.wordpress.com/
 
My Email: rashimiiuc at yahoo dot com
Follow on   Twitter   LinkedIn

Comments and Discussions

 
Questionother solution? PinmemberRockair20-Mar-12 8:41 
AnswerRe: other solution? PinmemberMd. Rashim uddin20-Mar-12 9:08 
GeneralRe: other solution? Pinmemberstooboo20-Mar-12 9:51 
GeneralRe: other solution? Pinmemberjohannesnestler20-Mar-12 10:42 
GeneralRe: other solution? Pinmemberstooboo20-Mar-12 10:50 
GeneralRe: other solution? Pinmemberstooboo20-Mar-12 10:52 
GeneralRe: other solution? Pinmemberjohannesnestler21-Mar-12 9:26 
GeneralRe: other solution? PinmemberPIEBALDconsult20-Mar-12 10:30 
QuestionWhy use DataContext? Pinmemberjklucker20-Mar-12 8:39 
GeneralMy Vote of 1 Pinmemberstooboo20-Mar-12 8:09 
GeneralRe: My Vote of 1 Pinmemberstooboo20-Mar-12 8:18 
GeneralRe: My Vote of 1 PinmemberMd. Rashim uddin20-Mar-12 8:52 
GeneralRe: My Vote of 1 Pinmemberstooboo20-Mar-12 9:54 
GeneralRe: My Vote of 1 PinmemberPIEBALDconsult20-Mar-12 12:07 
GeneralRe: My Vote of 1 Pinmemberstooboo20-Mar-12 12:33 
GeneralRe: My Vote of 1 PinmemberAndreas Gieriet20-Mar-12 13:12 
GeneralRe: My Vote of 1 PinmemberMahmud Hasan28-Mar-12 1:50 
GeneralRe: My Vote of 1 PinmemberAndreas Gieriet28-Mar-12 3:51 
GeneralRe: My Vote of 1 PinmemberPIEBALDconsult20-Mar-12 15:02 
GeneralRe: My Vote of 1 Pinmemberstooboo20-Mar-12 15:16 
GeneralRe: My Vote of 1 [modified] PinmemberAndreas Gieriet20-Mar-12 22:02 
GeneralRe: My Vote of 1 [modified] PinmemberAndreas Gieriet20-Mar-12 13:22 
GeneralRe: My Vote of 1 Pinmemberstooboo20-Mar-12 15:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.141223.1 | Last Updated 21 Mar 2012
Article Copyright 2012 by Md. Rashim uddin
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid