Click here to Skip to main content
15,885,546 members
Home / Discussions / C#
   

C#

 
AnswerRe: 'out' keyword, to use or not to use Pin
Pete O'Hanlon19-Apr-16 23:01
mvePete O'Hanlon19-Apr-16 23:01 
GeneralRe: 'out' keyword, to use or not to use Pin
Nathan Minier20-Apr-16 1:51
professionalNathan Minier20-Apr-16 1:51 
GeneralRe: 'out' keyword, to use or not to use Pin
Pete O'Hanlon20-Apr-16 2:06
mvePete O'Hanlon20-Apr-16 2:06 
GeneralRe: 'out' keyword, to use or not to use Pin
Nathan Minier20-Apr-16 2:17
professionalNathan Minier20-Apr-16 2:17 
GeneralRe: 'out' keyword, to use or not to use Pin
Pete O'Hanlon20-Apr-16 2:36
mvePete O'Hanlon20-Apr-16 2:36 
GeneralRe: 'out' keyword, to use or not to use Pin
Foothill20-Apr-16 3:42
professionalFoothill20-Apr-16 3:42 
GeneralRe: 'out' keyword, to use or not to use Pin
Richard Deeming20-Apr-16 4:19
mveRichard Deeming20-Apr-16 4:19 
AnswerRe: 'out' keyword, to use or not to use Pin
Ian A Davidson20-Apr-16 0:09
Ian A Davidson20-Apr-16 0:09 
Not a hard-and-fast rule, but I have often found that if I need an out or ref parameter, it indicates that my object model might be wrong.
Of course, it's not always easy, or possible, to get that entirely as you would like it, due to the interfaces that need to be used.

However, as perhaps a poor example (since you admit your example isn't the best), instead of:
C#
// Let's say that you run a search to see if a particular product was on sale
public bool IsProductOnSale(guid productId, out Guid[] productResellerIds)
{
  // This function runs a query against the database to see if this particular product has references in the 'on sale' reference table.
  // If it has references, it returns true also sets the array of resellers that sell that product.
  // The data for which seller has the item on sale is returned in the product query.
}


maybe you would consider having "Product" objects, instead of using a raw id. This could then contain all the information you need, and/or look it up as-and-when required:

e.g:

C#
class Product
{
    private Collection<Seller> resellers;
    public Collection<Seller> Resellers
    {
        if (null == resellers)
        {
           // Do your look-up, and set resellers accordingly (using interlock if necessary)
        }
        return resellers;
    }

    public bool IsProductOnSale()
    {
        return (Resellers.Count > 0);
    }

    // ...
}


Then you could do
if (myProduct.IsProductOnSale) { foreach (Seller in myProduct.Resellers) { ... }
without obtaining the information from the database twice. Your calling code doesn't even need to know how (or when) the information is retrieved - you might decide to do it in the constructor.

Your constructor for Product would probably take a guid... etc, etc.
GeneralRe: 'out' keyword, to use or not to use Pin
Foothill20-Apr-16 4:34
professionalFoothill20-Apr-16 4:34 
QuestionWhile button is clicked Pin
tvks19-Apr-16 8:30
tvks19-Apr-16 8:30 
AnswerRe: While button is clicked Pin
clapclap19-Apr-16 8:32
clapclap19-Apr-16 8:32 
AnswerRe: While button is clicked Pin
koolprasad200319-Apr-16 18:26
professionalkoolprasad200319-Apr-16 18:26 
GeneralRe: While button is clicked Pin
CHill6020-Apr-16 1:25
mveCHill6020-Apr-16 1:25 
GeneralRe: While button is clicked Pin
koolprasad200320-Apr-16 1:33
professionalkoolprasad200320-Apr-16 1:33 
AnswerRe: While button is clicked Pin
CHill6020-Apr-16 2:14
mveCHill6020-Apr-16 2:14 
PraiseRe: While button is clicked Pin
tvks20-Apr-16 10:57
tvks20-Apr-16 10:57 
GeneralRe: While button is clicked Pin
CHill6020-Apr-16 11:01
mveCHill6020-Apr-16 11:01 
GeneralRe: While button is clicked Pin
tvks27-Apr-16 2:55
tvks27-Apr-16 2:55 
QuestionReflection and "security" Pin
Super Lloyd19-Apr-16 7:17
Super Lloyd19-Apr-16 7:17 
QuestionLinkButton isnt recognized properly Pin
Collectoons19-Apr-16 4:19
Collectoons19-Apr-16 4:19 
SuggestionRe: LinkButton isnt recognized properly Pin
Richard MacCutchan19-Apr-16 5:09
mveRichard MacCutchan19-Apr-16 5:09 
GeneralRe: LinkButton isnt recognized properly Pin
Collectoons19-Apr-16 5:16
Collectoons19-Apr-16 5:16 
GeneralRe: LinkButton isnt recognized properly Pin
Richard MacCutchan19-Apr-16 5:26
mveRichard MacCutchan19-Apr-16 5:26 
AnswerRe: LinkButton isnt recognized properly Pin
Richard Deeming19-Apr-16 5:56
mveRichard Deeming19-Apr-16 5:56 
GeneralRe: LinkButton isnt recognized properly Pin
Collectoons19-Apr-16 6:03
Collectoons19-Apr-16 6:03 

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.