Out parameter

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sridharvenkataramanan
    New Member
    • May 2010
    • 7

    Out parameter

    Hi,
    I am recently using Fxcop , and in my application i used out parameter in a situation as described below. but Fxcop shows the message as
    "Using out parameters might indicate a design flaw."

    I have a method which returns the result set of database query as dictionary. I need to display the headings / [ the field selections used in the query for display purpose from the front end. so i used out put paramter to display the headings/selected fields of the query and dictionary to hold the records from database.
    Code:
    public Dictionary<int, LogHeader> FetchErrorLog(out ReadOnlyCollection<string> readOnlyColNames)
            {
    
                Dictionary<int, LogHeader> dicHeader = new Dictionary<int, LogHeader>();
    
      ..................
    
                List<string> colNames = new List<string>();
                
                colNames = new List<string>();
                colNames.Add("ErrorType");
                colNames.Add("Description");
                colNames.Add("Computer");
                colNames.Add("Created");
    
                readOnlyColNames = new ReadOnlyCollection<string>(colNames);
    
    }
    Let me know what is the other way to return the headings of the query as well the resultant records .
    Last edited by Niheel; Jun 3 '10, 10:15 AM. Reason: use code tags to post code please
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    I think what you did is fine. But if you really want to get rid of the out param you could make a new class with two properties: headings list, dictionary.

    Then return a new instance of the class with your fetched objects.

    Comment

    Working...