|
Why doesn't he just generate the same guid again and compare?
|
|
|
|
|
Exactly. Ought to be
Guid invalid = Guid.Empty();
if (userQueryID.ToString().ToUpper() != invalid.ToString().ToUpper());return null; Oops;! Happened to add another feature...
|
|
|
|
|
Is the errant semi-colon on purpose?
You'll never get very far if all you do is follow instructions.
|
|
|
|
|
Don't fix that! Other places using that function meanwhile rely on its "feature" that it returns a *special* list for Guid.Empty()!
|
|
|
|
|
Bernhard Hiller wrote: it returns a *special* list for Guid.Empty()!
It's expected to, but does it?
You'll never get very far if all you do is follow instructions.
|
|
|
|
|
IIRC guid's are value not reference types so they can't be empty. Doesn't it have hasValue() method or some such?
|
|
|
|
|
They can't be null, but they can be empty, which is the guid equivalent of zero.
http://msdn.microsoft.com/en-us/library/system.guid.empty.aspx[^]
There's no HasValue property or method; you just need to test whether it's equal to Guid.Empty .
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Richard Deeming wrote: you just need to test whether it's equal to Guid.Empty
Except for that you probably don't actually need to.
Edit:
I'm also suspicious as to whether or not they're actually using System.Guid . The snippet doesn't specify, so it's possible that they rolled their own Guid class and then all bets are off.
You'll never get very far if all you do is follow instructions.
modified 27-Jun-14 10:41am.
|
|
|
|
|
Well, you do if you want to know whether or not it's empty.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Except you probably don't actually need to.
You'll never get very far if all you do is follow instructions.
|
|
|
|
|
Google for 'Index Of' instead of 'IndexOf'.
Those are some strange images in the results. (click) NSFW!!!
What the ____?
|
|
|
|
|
I am not sure how to handle that Exception.
Simon Lee Shugar (Software Developer)
www.simonshugar.co.uk
"If something goes by a false name, would it mean that thing is fake? False by nature?" By Gilbert Durandil
|
|
|
|
|
And if you Google 'Parent Directory' you get a different set of similar pictures.
.
|
|
|
|
|
Looks like "parental control" failed in those cases.
|
|
|
|
|
No. It means "get me the contents of the directory meant only for parents"
|
|
|
|
|
Someone's left "directory browsing" turned on for their - ahem - "gentlemen's special-interest" site?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
If only I had know what NSFW meant before I tried this... thanks for that
|
|
|
|
|
Newb!
You could have just typed "define NSFW" into Google and found out!
|
|
|
|
|
Dave Kreskowiak wrote: You could have just typed "define NSFW" into Google and found out!
I did... afterwards. During the first read I didn't think much of it
|
|
|
|
|
Well, sounds like you have gotten an education in more ways than one
Just because the code works, it doesn't mean that it is good code.
|
|
|
|
|
|
Means that 99.9% of all the servers on the internet have porn
|
|
|
|
|
I was in a training course last week where the below code was used as part of an example. It was described as a method that would generate a unique ID and add the specified prefix to it.
public static String generateId(String prefix)
{
int randomNumber = new Random().nextInt();
String id = Integer.toString(randomNumber);
if(id.startsWith("-"))
{
id = id.replace('-', '3');
id = prefix + id;
}
return id;
}
Apart from the flaws that I'm sure you'll spot, I should point out that this was in the context of server-side code that forms part of a workflow. So depending on how often the workflow executes, it could be likely that multiple instances of the workflow would execute at the same time and generate the same "unique" ID.
What is this talk of release? I do not release software. My software escapes leaving a bloody trail of designers and quality assurance people in its wake.
|
|
|
|
|
BotCar wrote: ... multiple instances of the workflow would execute at the same time and generate the same "unique" ID. It's worse than that. Many implementations of Random() use a fixed seed by default, so the first value returned is effectively constant.
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
That's interesting. I did not realize that.
Do you mean that some languages' implementations of pseudorandom number generators uses fixed seeds, or that some implementations of the Java Virtual Machine uses fixed seeds by default?
What is this talk of release? I do not release software. My software escapes leaving a bloody trail of designers and quality assurance people in its wake.
|
|
|
|