Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7573441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:11:00+00:00 2026-05-30T16:11:00+00:00

I’m discussing different implementing techniques with a colleague Alternative A User user; if (users.TryGet(1,

  • 0

I’m discussing different implementing techniques with a colleague

Alternative A

User user;
if (users.TryGet(1, out user))
    Console.WriteLine(user.ToString()); 
else
    Console.WriteLine("Failed to get user.."); 

Alternative B

ResultSet<User> result = users.Get(1); 
if(result.OK)
    Console.WriteLine(user.ToString()); 
else
    Console.WriteLine("Failed to get user.."); 

Alternative A is similar in behaviour as int.Parse(string, out value) and is easy to extend and read. Adding more objects to the output when success seems easy and readable.

Alternative B seems a bit more convoluted in that there is more code on each line. But can be extended to include other information in the ResultSet as well as the object back. Is it more difficult to return more than one object or any ideas regarding workarounds?

Is it considered ugly/bad practice to use out parameters like that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T16:11:02+00:00Added an answer on May 30, 2026 at 4:11 pm

    In general, Microsoft discourages using out-parameters in public methods. A proper approach would be to throw an exception if a method fails to do the job identified by its name. In this case, if the Get method is unable to Get the data record, there should be an exception. If this situation is occuring very frequently, you could use Alternative B to improve performance a little bit in contrast to throwing exceptions every time.

    As for Alternative A, method should be named TryGet in this case to be consistent with FCL naming conventions (TryParse, TryGetValue etc.).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.