Click here to Skip to main content
16,011,170 members
Home / Discussions / C#
   

C#

 
AnswerRe: Partial Snippet Pin
OriginalGriff19-Apr-14 4:31
mveOriginalGriff19-Apr-14 4:31 
Questiona concept I'm trying to build Pin
solo918-Apr-14 15:07
solo918-Apr-14 15:07 
GeneralRe: a concept I'm trying to build Pin
Richard MacCutchan18-Apr-14 21:57
mveRichard MacCutchan18-Apr-14 21:57 
Questioni want to hyperlink connect with stringquery and also display same hyperlink on other page Pin
Member 1061806718-Apr-14 12:12
Member 1061806718-Apr-14 12:12 
AnswerRe: i want to hyperlink connect with stringquery and also display same hyperlink on other page Pin
Richard Andrew x6418-Apr-14 12:19
professionalRichard Andrew x6418-Apr-14 12:19 
GeneralRe: i want to hyperlink connect with stringquery and also display same hyperlink on other page Pin
Member 1061806718-Apr-14 12:40
Member 1061806718-Apr-14 12:40 
GeneralRe: i want to hyperlink connect with stringquery and also display same hyperlink on other page Pin
Richard Andrew x6418-Apr-14 12:54
professionalRichard Andrew x6418-Apr-14 12:54 
QuestionProperty with "get" only, or a separate method? Pin
Matt U.18-Apr-14 8:09
Matt U.18-Apr-14 8:09 
So I was discussing this subject with one of my coworkers after he asked me to review some of his code. Our software breaks apart data files, and feeds them to a separate service to be stored in a SQL Server database. His "Record" class has several properties for each of the fields in the client's data file. This particular client's module uses the FileHelpers utility library to read a CSV format, so we're not parsing it manually. Three of the fields are: City, State, ZIP.

Ultimately, we only really care to access the City/State/ZIP as a whole, a formatted string (e.g. Small-Town, USA 12345). With that being said, does it make more sense to loop over a collection of records and call a method like so:

C#
private void SetCityStateZip(Record myRecord)
{
    myRecord.CityStateZip = string.Format("{0}, {1} {2}", myRecord.City, myRecord.State, myRecord.Zip);
}


"CityStateZip" is a property in the Record class, referencing a field "_cityStateZip".

Or does it make more sense, instead of creating a whole new field/property, to use a property with a getter that contains the logic as follows:

C#
public string CityStateZip
{
    get
    {
        return string.Format("{0}, {1} {2}", _city, _state, _zip);
    }
}


I ask because to me, it makes sense to use the getter with simple logic, as opposed to a separate method. Why? Because CityStateZip is only accessed once for each record when the processing service takes place. The individual City/State/ZIP properties are not used elsewhere.

I figured, for the sake of example, if a data file has 10,000 records, and you call the "SetCityStateZip" method for each, you're setting 10,000 "CityStateZip" properties well before it's even used. There are actually TWO properties like this, so that's 20,000 fields/properties being set when they're each only referenced once in processing. Why assign extra "string" values?

Hope this makes sense. Kind of typed it in a hurry. Just wanting some feedback, as a coworker stated that he believes it's a bad idea to use logic in getters. If he is correct, so be it. But I sometimes enjoy a second/third/fourth/nth. opinion. Wink | ;)
djj55: Nice but may have a permission problem
Pete O'Hanlon: He has my permission to run it.

AnswerRe: Property with "get" only, or a separate method? Pin
OriginalGriff18-Apr-14 8:15
mveOriginalGriff18-Apr-14 8:15 
GeneralRe: Property with "get" only, or a separate method? Pin
Matt U.18-Apr-14 8:16
Matt U.18-Apr-14 8:16 
GeneralRe: Property with "get" only, or a separate method? Pin
OriginalGriff18-Apr-14 8:32
mveOriginalGriff18-Apr-14 8:32 
AnswerRe: Property with "get" only, or a separate method? Pin
Ravi Bhavnani18-Apr-14 8:16
professionalRavi Bhavnani18-Apr-14 8:16 
GeneralRe: Property with "get" only, or a separate method? Pin
Matt U.18-Apr-14 8:19
Matt U.18-Apr-14 8:19 
GeneralRe: Property with "get" only, or a separate method? Pin
Ravi Bhavnani18-Apr-14 8:59
professionalRavi Bhavnani18-Apr-14 8:59 
Questionmarching cubes Pin
Member 1071125918-Apr-14 7:25
Member 1071125918-Apr-14 7:25 
AnswerRe: marching cubes Pin
OriginalGriff18-Apr-14 8:10
mveOriginalGriff18-Apr-14 8:10 
QuestionBackground Substraction and HOG Pin
Member 1042078418-Apr-14 5:42
Member 1042078418-Apr-14 5:42 
QuestionDisplay graph from selected dropdownlist and radiobutton Pin
Syafiqah Zahirah18-Apr-14 0:43
Syafiqah Zahirah18-Apr-14 0:43 
QuestionCS1525: Invalid expression term '<' error Pin
Member 1075622017-Apr-14 6:12
Member 1075622017-Apr-14 6:12 
AnswerRe: CS1525: Invalid expression term '<' error Pin
Wes Aday17-Apr-14 6:29
professionalWes Aday17-Apr-14 6:29 
GeneralRe: CS1525: Invalid expression term '<' error Pin
OriginalGriff17-Apr-14 8:26
mveOriginalGriff17-Apr-14 8:26 
GeneralRe: CS1525: Invalid expression term '<' error Pin
Richard MacCutchan17-Apr-14 22:16
mveRichard MacCutchan17-Apr-14 22:16 
Questionquestion abot WPF Button Pin
Member 1026763017-Apr-14 3:44
Member 1026763017-Apr-14 3:44 
GeneralRe: question abot WPF Button Pin
Richard MacCutchan17-Apr-14 5:32
mveRichard MacCutchan17-Apr-14 5:32 
GeneralRe: question abot WPF Button Pin
Richard Andrew x6417-Apr-14 8:51
professionalRichard Andrew x6417-Apr-14 8: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.