Click here to Skip to main content
15,881,709 members
Home / Discussions / C#
   

C#

 
AnswerRe: 'out' keyword, to use or not to use Pin
clapclap19-Apr-16 9:05
clapclap19-Apr-16 9:05 
GeneralRe: 'out' keyword, to use or not to use Pin
Foothill19-Apr-16 9:24
professionalFoothill19-Apr-16 9:24 
GeneralRe: 'out' keyword, to use or not to use Pin
Sascha Lefèvre19-Apr-16 9:29
professionalSascha Lefèvre19-Apr-16 9:29 
GeneralRe: 'out' keyword, to use or not to use Pin
Foothill19-Apr-16 9:51
professionalFoothill19-Apr-16 9:51 
GeneralRe: 'out' keyword, to use or not to use Pin
F-ES Sitecore21-Apr-16 0:26
professionalF-ES Sitecore21-Apr-16 0:26 
AnswerRe: 'out' keyword, to use or not to use Pin
Sander Rossel19-Apr-16 11:08
professionalSander Rossel19-Apr-16 11:08 
GeneralRe: 'out' keyword, to use or not to use Pin
Foothill19-Apr-16 11:38
professionalFoothill19-Apr-16 11:38 
GeneralRe: 'out' keyword, to use or not to use Pin
Sander Rossel19-Apr-16 12:24
professionalSander Rossel19-Apr-16 12:24 
Foothill wrote:
Let me see if I can give a better example. Let's go with an web environment that supports both internal and external user logon.
I'm not sure I get what your function is doing. If the user has no access what happens to the principal (null, default/anonymous implementation)? Can the method return true and still set principal to null or return false and set the principal anyway? What if you decide for an anonymous principal (or whatever) instead, will it always return true? I'd have to read the documentation and trust it's correct (and I never trust documentation).

I'd expect (and prefer) something like the following, although I'm not sure how this would work out in actual code:
C#
public static UserPrincipal GetPrincipal(string userName)
{
   if (UserIsAuthorized(userName))
   {
      return new UserPrincipal();
   }
   else
   {
      return null;
   }
}
That code makes it pretty explicit that there is or isn't a UserPrincipal for a userName. The function now does one thing (retrieve the principal if it exists) and the function name makes it clear. There is also one less variable to worry about (which eliminates the questions I raised earlier).

Foothill wrote:
The deeper I delve into C# and .Net, the more contradictions I find.
Many people worked on it and all had their own ideas and experiences. That .NET does it like this doesn't mean it's good or makes sense. Or maybe it does, but we don't know why Smile | :)
I'd prefer the byte[] rndArr = rand.GetBytes(n); approach, but you might have guessed that Smile | :)
Read my (free) ebook Object-Oriented Programming in C# Succinctly.
Visit my blog at Sander's bits - Writing the code you need.
Or read my articles here on CodeProject.
Simplicity is prerequisite for reliability.
— Edsger W. Dijkstra
Regards,
Sander

GeneralRe: 'out' keyword, to use or not to use Pin
Foothill19-Apr-16 14:06
professionalFoothill19-Apr-16 14:06 
GeneralRe: 'out' keyword, to use or not to use Pin
Sander Rossel19-Apr-16 21:25
professionalSander Rossel19-Apr-16 21:25 
GeneralRe: 'out' keyword, to use or not to use Pin
Foothill20-Apr-16 5:14
professionalFoothill20-Apr-16 5:14 
GeneralRe: 'out' keyword, to use or not to use Pin
Brisingr Aerowing20-Apr-16 4:23
professionalBrisingr Aerowing20-Apr-16 4:23 
GeneralRe: 'out' keyword, to use or not to use Pin
F-ES Sitecore21-Apr-16 0:33
professionalF-ES Sitecore21-Apr-16 0:33 
GeneralRe: 'out' keyword, to use or not to use Pin
Foothill21-Apr-16 4:39
professionalFoothill21-Apr-16 4:39 
GeneralRe: 'out' keyword, to use or not to use Pin
Richard MacCutchan19-Apr-16 20:46
mveRichard MacCutchan19-Apr-16 20:46 
GeneralRe: 'out' keyword, to use or not to use Pin
Sander Rossel19-Apr-16 21:26
professionalSander Rossel19-Apr-16 21:26 
GeneralRe: 'out' keyword, to use or not to use Pin
Mycroft Holmes19-Apr-16 21:54
professionalMycroft Holmes19-Apr-16 21:54 
GeneralRe: 'out' keyword, to use or not to use Pin
Foothill20-Apr-16 5:03
professionalFoothill20-Apr-16 5:03 
GeneralRe: 'out' keyword, to use or not to use Pin
Sander Rossel20-Apr-16 5:59
professionalSander Rossel20-Apr-16 5:59 
AnswerRe: 'out' keyword, to use or not to use Pin
Gerry Schmitz19-Apr-16 12:36
mveGerry Schmitz19-Apr-16 12:36 
AnswerRe: 'out' keyword, to use or not to use Pin
Bernhard Hiller19-Apr-16 21:25
Bernhard Hiller19-Apr-16 21:25 
GeneralRe: 'out' keyword, to use or not to use Pin
Foothill20-Apr-16 3:16
professionalFoothill20-Apr-16 3:16 
AnswerRe: 'out' keyword, to use or not to use Pin
V.19-Apr-16 22:04
professionalV.19-Apr-16 22:04 
GeneralRe: 'out' keyword, to use or not to use Pin
Foothill20-Apr-16 3:13
professionalFoothill20-Apr-16 3:13 
AnswerRe: 'out' keyword, to use or not to use Pin
OriginalGriff19-Apr-16 23:00
mveOriginalGriff19-Apr-16 23:00 

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.