|
I think this improves the code a lot… Extra precisions and conversions to make sure we're getting exactly what we want.
((Decimal)Convert.ToDecimal(chkdate.Length.ToString()) != (Decimal)Convert.ToDecimal(((Decimal)(11.0000000000000000000000000000)).ToString())).ToString() == Boolean.TrueString;
The optimizing JITter is going to have fun with this one…
ROFLOLMFAO
|
|
|
|
|
You left out the string.compare call with the ignore case option, and specifying the CultureInfo on the ToString calls.
This blanket smells like ham
|
|
|
|
|
He could've written:
if (Convert.ToChar(chkdate.Length.ToString().ToCharArray()[0]) != new String("1").ToCharArray()[0])
{
if (Convert.ToChar(chkdate.Length.ToString().ToCharArray()[1]) != new String("1").ToCharArray()[0])
{
return false;
}
}
xacc.ideIronScheme a R5RS-compliant Scheme on the DLR
The rule of three: "The first time you notice something that might repeat, don't generalize it. The second time the situation occurs, develop in a similar fashion -- possibly even copy/paste -- but don't generalize yet. On the third time, look to generalize the approach."
|
|
|
|
|
Except you forgot to convert the char types to some int type to ensure it would be a numeric comparison.
|
|
|
|
|
leppie wrote: if (Convert.ToChar(chkdate.Length.ToString().ToCharArray()[0]) != new String("1").ToCharArray()[0]){ if (Convert.ToChar(chkdate.Length.ToString().ToCharArray()[1]) != new String("1").ToCharArray()[0]) { return false; }}
Not so fast, your code does not work while his does.
[Hint] Your code will not return false for strings of length 1, 10, 101, etc.
|
|
|
|
|
Of course not ! Thats an exercise for the next poor soul that works on the code :p
xacc.ideIronScheme a R5RS-compliant Scheme on the DLR
The rule of three: "The first time you notice something that might repeat, don't generalize it. The second time the situation occurs, develop in a similar fashion -- possibly even copy/paste -- but don't generalize yet. On the third time, look to generalize the approach."
|
|
|
|
|
Pete O`Hanlon wrote: ://it checks it contains 11 char (dd/MMM/yyyy)
if (Convert.ToInt16(chkdate.Length.ToString()).ToString() != "11")
{
//if it does not have 11 char then it will return false
return false;
}
Fixed
|
|
|
|
|
Is this what they call optimized code?
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->ßRÅhmmÃ<-·´¯`·.
|
|
|
|
|
For checking whether the string contains a valid date the code is crap. (SCNR)
This shows what the results of "high level" programming languages are.
Greetings from Germany
|
|
|
|
|
KarstenK wrote: This shows what the results of "high level" programming languages are
Idiot developers who shouldn't be let anywhere near a keyboard without being wired up to the mains and given a shock everytime they produce crap like this.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Then even the lead developer would be shocking.
Ninja (the Nerd)
Confused? You will be...
|
|
|
|
|
Why can't not ONE of you folkes be grown up enough to simply say that the rubbish:
://it checks if it contains 11 char (dd/MMM/yyyy)
if (Convert.ToInt16(chkdate.Length.ToString()) != 11)
{
// Do something if not.
}
SHOULD be:
:// it checks if it contains 11 char (dd/MMM/yyyy)
if (chkdate.Length != 11)
{
// Do something if not.
}
How hard can it be?
It's OK to pinpoint bad code like that but it's not OK not to come up with a useable alternative.
Michael M., mm it-consult dk.
|
|
|
|
|
Michael Mogensen wrote: Why can't not ONE of you folkes be grown up enough to simply say...
Michael,
Is your sense of humor having a bad day?
But if we are geting serious, I'd like to point out that your question contains a double negative and means the opposite of your apparent intended meaning.
|
|
|
|
|
Pete O`Hanlon wrote: :
<br />
if (Convert.ToInt16(chkdate.Length.ToString()) != 11)<br />
{<br />
return false;<br />
}<br />
Shouldn't the comparison do this?
<br />
if (chkdate.Length.ToString() != "11")<br />
|
|
|
|
|
...Double negative... I give up... SS... forget it...
Not beeing 100% into C# (I'm c/cpp) I suppose that this issue is something in the area of 'to get the types right' right? (ough double 'right' ... sorry)
If this is string: chkdate, then this is int: chkdate.length and then I compare 11 to int which is ok, or?
Michael M., mm it-consult dk.
|
|
|
|
|
Michael,
I'm far from 100% into C#, like you, I'm a c/c++ guy. (We still have lots of stuff that's says it's c++ but it's mostly old style C).
Anyway, this is an issue of getting the types right. And I was just being a smart alec.
-- Tony
|
|
|
|
|
i am doing a proj to implement quantum encryption in a vb appln. i just need a best algorithm for doin that.. pls help me soon as my proj dates are coming closer....
Thank u,
Freak8802
|
|
|
|
|
FREAK8802 wrote: implement quantum encryption in a vb appln
I think you are going to need a very small chisel and hammer.
xacc.ideIronScheme a R5RS-compliant Scheme on the DLR
The rule of three: "The first time you notice something that might repeat, don't generalize it. The second time the situation occurs, develop in a similar fashion -- possibly even copy/paste -- but don't generalize yet. On the third time, look to generalize the approach."
|
|
|
|
|
No need. All VB apps are quantum encrypted anyway.
Or did I mean 'a quantity of cr*p'?
Phil
The opinions expressed in this post are not necessarily those of the author, especially if you find them impolite, inaccurate or inflammatory.
|
|
|
|
|
FREAK8802 wrote: proj dates are coming closer
don't worry, quantum encryption runs at the speed of light.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Hi. Tell you what, you tell me the secret password, the number I'm thinking of and 1 valid reason why I should give this information to you from THIS forum, and I'll oblige.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Pete O`Hanlon wrote: Tell you what, you tell me the secret password
cheesynipple
Pete O`Hanlon wrote: the number I'm thinking of
42
Pete O`Hanlon wrote: and 1 valid reason why I should give this information to you from THIS forum
I'll give you a free pie
My current favourite word is: PIE!
Good ol' pie, it's been a while.
|
|
|
|
|
The Undefeated wrote: I'll give you a free pie
that won't cut it, IMO Pete wants a waffle, but I know you ran out.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
The Undefeated wrote: cheesynipple
That's so gross - BTW that's the counter reply to cheesynipple.
The Undefeated wrote: 42
Correct.
The Undefeated wrote: I'll give you a free pie
Now, had you said you'd give me two free pies or one waffle and you would have got the code for free.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
The Undefeated wrote: Pete O`Hanlon wrote:
the number I'm thinking of
42
Like there is another number
codito ergo sum
|
|
|
|