Click here to Skip to main content
15,899,314 members
Home / Discussions / C#
   

C#

 
QuestionDisplay Datetime As per GMT Pin
Sun Rays1-May-09 19:35
Sun Rays1-May-09 19:35 
QuestionHow to connect excel database Pin
kaushik_dass1-May-09 19:34
kaushik_dass1-May-09 19:34 
AnswerRe: How to connect excel database Pin
Sun Rays1-May-09 19:38
Sun Rays1-May-09 19:38 
QuestionNoob question: Displaying a List in a ListView Pin
Quake2Player1-May-09 19:00
Quake2Player1-May-09 19:00 
AnswerRe: Noob question: Displaying a List in a ListView Pin
Member 10339071-May-09 22:34
Member 10339071-May-09 22:34 
AnswerRe: Noob question: Displaying a List in a ListView Pin
DaveyM691-May-09 23:24
professionalDaveyM691-May-09 23:24 
GeneralRe: Noob question: Displaying a List in a ListView Pin
Quake2Player2-May-09 8:41
Quake2Player2-May-09 8:41 
GeneralRe: Noob question: Displaying a List in a ListView Pin
DaveyM693-May-09 0:28
professionalDaveyM693-May-09 0:28 
If you want name in a different column then add it as a sub item.

Your other point is a good question. It depends on just how fussy you want/need to be.

Quake2Player wrote:
Is it ok to return a ListView


Making the Person class reliant on a list view would be a bad idea:
// DO NOT do this!
public void AddToListView(ListView listView)
{
    ListViewItem listViewItem = new ListViewItem(Name);
    // ...
    listView.Items.Add(listViewItem);
}
but in my opinion, returning a ListViewItem from the class is OK as it doesn't rely on any existing object instance to be able to perform the method. I would draw the line at a ListViewItem (or a List<ListViewItem> or ListViewItem[] for a collection), returning an entire ListView would be taking it too far.

Not everyone would agree that returning a ListViewItem is OK - if this is for work/college, ask your boss/tutor for their opinion. The way you were doing it is good, but the reusability of having a method like that in the class (especially if it's going to be used a lot) can be advantageous.

Another minor thing that's often worth doing (along the same lines) is to override the ToString method e.g.
public override string ToString()
{
    return string.Format("Name: {0}, Age: {1}", Name, Age);
}
This is a very standard thing to do and not that disimilar to what I suggested.

Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
Why are you using VB6? Do you hate yourself? (Christian Graus)

QuestionDateTime problem Pin
soulidentities1-May-09 17:26
soulidentities1-May-09 17:26 
AnswerRe: DateTime problem Pin
Garth J Lancaster1-May-09 18:29
professionalGarth J Lancaster1-May-09 18:29 
GeneralRe: DateTime problem Pin
J4amieC1-May-09 22:56
J4amieC1-May-09 22:56 
GeneralRe: DateTime problem Pin
Garth J Lancaster1-May-09 23:58
professionalGarth J Lancaster1-May-09 23:58 
AnswerRe: DateTime problem Pin
J4amieC1-May-09 22:59
J4amieC1-May-09 22:59 
GeneralRe: DateTime problem Pin
soulidentities2-May-09 14:59
soulidentities2-May-09 14:59 
Questionconnect four Pin
Marwa Shams1-May-09 17:25
Marwa Shams1-May-09 17:25 
AnswerRe: connect four Pin
Garth J Lancaster1-May-09 18:36
professionalGarth J Lancaster1-May-09 18:36 
GeneralRe: connect four Pin
Member 10339071-May-09 22:36
Member 10339071-May-09 22:36 
GeneralRe: connect four Pin
Garth J Lancaster1-May-09 23:54
professionalGarth J Lancaster1-May-09 23:54 
GeneralRe: connect four Pin
Member 10339072-May-09 0:30
Member 10339072-May-09 0:30 
GeneralRe: connect four Pin
Pete O'Hanlon2-May-09 10:06
mvePete O'Hanlon2-May-09 10:06 
QuestionNeed help using visual studio and C# to make a simple app that displays html Pin
devsfan18301-May-09 13:54
devsfan18301-May-09 13:54 
AnswerRe: Need help using visual studio and C# to make a simple app that displays html Pin
Anthony Mushrow1-May-09 14:47
professionalAnthony Mushrow1-May-09 14:47 
GeneralRe: Need help using visual studio and C# to make a simple app that displays html [modified] Pin
devsfan18301-May-09 15:53
devsfan18301-May-09 15:53 
GeneralRe: Need help using visual studio and C# to make a simple app that displays html Pin
Anthony Mushrow2-May-09 0:55
professionalAnthony Mushrow2-May-09 0:55 
QuestionHow to debug COM+ Applications Using Microsoft .NET Enterprise Services ?? Pin
Yanshof1-May-09 13:51
Yanshof1-May-09 13:51 

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

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