|
6/20/2008 11:30:10 PM
|
OnlyMaverick Posts 9
|
Haha, apologize for the typo.
Cheers 
Ken Cox wrote:
OnlyMaverick wrote: enClr = new System.Drawing.KnowingColor();
Knowing? Are you sure about that? That's one heckuva fix!  Ken
|
|
6/20/2008 10:56:28 PM
|
Ken Cox Posts 170
|
OnlyMaverick wrote:
enClr = new System.Drawing.KnowingColor();
Knowing? Are you sure about that? That's one heckuva fix! 
Ken
|
|
6/20/2008 4:41:33 AM
|
OnlyMaverick Posts 9
|
wtetlow wrote:
clrs.AddRange((System.Collections.Generic.IEnumerable<System.Drawing.KnownColor>  System.Enum.GetValues(enClr.GetType())); will also work. I wish I had read this thread before struggling to find an answer on my own.
Ok this makes sense but I actually got an error message saying "unassigned local variable enClr"
Then I had to allocate memory to the enClr = new System.Drawing.KnowingColor();
I wish i didn't have to allocate memory
Thanks again , it finally worked
|
|
6/20/2008 4:39:57 AM
|
OnlyMaverick Posts 9
|
wtetlow wrote:
clrs.AddRange((System.Collections.Generic.IEnumerable<System.Drawing.KnownColor>  System.Enum.GetValues(enClr.GetType())); will also work. I wish I had read this thread before struggling to find an answer on my own.
Ok this makes sense but I actually got an error message saying "unassigned local variable enClr"
Then I had to allocate memory to the enClr = new System.Drawing.KnowingColor();
I wish i didn't have to allocate memory
Thanks again , it finally worked  edited by OnlyMaverick on 6/20/2008
|
|
6/18/2008 2:28:01 AM
|
OnlyMaverick Posts 9
|
thank you for the C# entry. is there C# code for the other pages as well?
wtetlow wrote:
Here's a little shorter version to overcome the "IsDate not in C#" issue: protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args) { DateTime x = new DateTime(); args.IsValid = DateTime.TryParse(args.Value, out x); } dgraper wrote: wtetlow:
My copy of the book only has 404 pages so perhaps you're referencing another book's page 779?
Another small modification for reading along with the book in C# -- there's another VB coder at my site who's started reading this book and he got stuck on pg. 59 when he discovered the ISDATE() function isn't supported by C#. His solution was kludgy, bringing in the MICROSOFT.SYSTEM.VBNET() library or something like that, but it seemed more elegant to just include an ISDATE() function in the code:
public static bool IsDate(string strDate) { DateTime dtDate; bool bValid = true; try { dtDate = DateTime.Parse(strDate); } catch (FormatException eFormatException) { // the Parse method failed => the string strDate cannot be converted to a date. bValid = false; } return bValid; }
I can't claim credit for the function, I copied it from some newgroup posting and keep it in a class library that I include in my projects as a crutch as I transition from VB to C#.
As regards other comment -- it would be nice to have a C# version of all the code available for download. At my site we're all being forced to move over to C# and as I mentioned I've already found someone else quietly reading this book, there are probably more. I'll tell them about this website, perhaps something can be pieced together from notes in this thread.
Thanks again! - Dave
|
|
4/14/2008 3:43:33 PM
|
Ken Cox Posts 170
|
dgraper wrote:
Perhaps I used the inappropriate adverb ... it seemed more apropos than "surreptitiously," though.
Like you, I have problems with the "Dummies" stigma. Of course it's easier to be seen with a Dummies book if the boss knows you're mainly competent but trying to get up to speed on the latest and greatest.
The title aside, it's hard to argue with success of the Dummies franchise. There's hardly a topic they don't touch. Hmmm. I don't think I've seen "Porn For Dummies" yet. 
Ken
|
|
4/13/2008 2:28:59 PM
|
dgraper Posts 4
|
Perhaps I used the inappropriate adverb ... it seemed more apropos than "surreptitiously," though.
If I might go off-topic for just a moment: While I feel this is an excellent introductory book, its cover can frighten pointy-haired-boss-types who wander by our cubicles with their friends pointing out their high-paid consultants. (That's "high-paid" only in their view -- when compared to the student interns and body-shop programmers they've come to prefer.) The other coder I discovered reading the book was keeping it under a pile of IBM Redbooks and immediately said that he was reading it "just to get his feet wet" as if it was a porno magazine. I too have contemplated removing the cover.
Perhaps it would have been wiser for me to save this information about my co-worker for potential blackmail use in the future but I admitted I too was reading it, it really stands out as a resource for developers wanting to learn ASP.NET 3.5 quickly.
|
|
4/13/2008 2:03:03 PM
|
wtetlow Posts 6
|
Here's a little shorter version to overcome the "IsDate not in C#" issue: protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args) { DateTime x = new DateTime(); args.IsValid = DateTime.TryParse(args.Value, out x); } dgraper wrote:
wtetlow:
My copy of the book only has 404 pages so perhaps you're referencing another book's page 779?
Another small modification for reading along with the book in C# -- there's another VB coder at my site who's started reading this book and he got stuck on pg. 59 when he discovered the ISDATE() function isn't supported by C#. His solution was kludgy, bringing in the MICROSOFT.SYSTEM.VBNET() library or something like that, but it seemed more elegant to just include an ISDATE() function in the code:
public static bool IsDate(string strDate) { DateTime dtDate; bool bValid = true; try { dtDate = DateTime.Parse(strDate); } catch (FormatException eFormatException) { // the Parse method failed => the string strDate cannot be converted to a date. bValid = false; } return bValid; }
I can't claim credit for the function, I copied it from some newgroup posting and keep it in a class library that I include in my projects as a crutch as I transition from VB to C#.
As regards other comment -- it would be nice to have a C# version of all the code available for download. At my site we're all being forced to move over to C# and as I mentioned I've already found someone else quietly reading this book, there are probably more. I'll tell them about this website, perhaps something can be pieced together from notes in this thread.
Thanks again! - Dave
|
|
4/13/2008 1:00:57 PM
|
Ken Cox Posts 170
|
wtetlow wrote:
someone else quietly reading this book
At least they're reading quietly!
Still, it's hard to work with someone in the next cube reading a computer book out loud. The funny parts are okay, but listening to a recitation of listings really wrecks my concentration.
|
|
4/13/2008 12:57:08 PM
|
Ken Cox Posts 170
|
Hi Dave,
Thanks for the conversion - all contributions gratefully received!
I did have it in mind to produce C# versions of all the listings as soon as the book was sent to the printer. Unfortunately (and fortunately!), I got very busy with a nice Web site contract and time seems to be short these days.
Perhaps I should create a forum where guys can post C# snippets with page references.
Oh, and that page reference should have been 379. 
Ken
|
|
4/13/2008 12:48:21 PM
|
dgraper Posts 4
|
wtetlow:
My copy of the book only has 404 pages so perhaps you're referencing another book's page 779?
Another small modification for reading along with the book in C# -- there's another VB coder at my site who's started reading this book and he got stuck on pg. 59 when he discovered the ISDATE() function isn't supported by C#. His solution was kludgy, bringing in the MICROSOFT.SYSTEM.VBNET() library or something like that, but it seemed more elegant to just include an ISDATE() function in the code:
public static bool IsDate(string strDate) { DateTime dtDate; bool bValid = true; try { dtDate = DateTime.Parse(strDate); } catch (FormatException eFormatException) { // the Parse method failed => the string strDate cannot be converted to a date. bValid = false; } return bValid; }
I can't claim credit for the function, I copied it from some newgroup posting and keep it in a class library that I include in my projects as a crutch as I transition from VB to C#.
As regards other comment -- it would be nice to have a C# version of all the code available for download. At my site we're all being forced to move over to C# and as I mentioned I've already found someone else quietly reading this book, there are probably more. I'll tell them about this website, perhaps something can be pieced together from notes in this thread.
Thanks again! - Dave
|
|
4/11/2008 9:23:46 PM
|
Ken Cox Posts 170
|
wtetlow wrote:
clrs.AddRange((System.Collections.Generic.IEnumerable<System.Drawing.KnownColor>  System.Enum.GetValues(enClr.GetType())); will also work. I wish I had read this thread before struggling to find an answer on my own.
I hear you! See Page 779, "Stop Bashing Your Head against a Wall" 
My trick in the past has been to take my VB code, compile it and look at the decompiled version as C# using Reflector!
|
|
4/11/2008 6:29:35 PM
|
wtetlow Posts 6
|
clrs.AddRange((System.Collections.Generic.IEnumerable<System.Drawing.KnownColor> System.Enum.GetValues(enClr.GetType())); will also work. I wish I had read this thread before struggling to find an answer on my own.
|
|
4/7/2008 10:45:21 AM
|
Ken Cox Posts 170
|
Hi Dave,
Glad to see you found an answer, and thanks for providing it here! 
Like you, I'm a VB guy who is working in C# on projects. Most of the time IntelliSense gets me through the syntax and case-sensitive nonsense. However, I wouldn't have known where to start with that enum thingy.
Oh, and once you get all the book's code translated from VB to C#, you're welcome to pass it along. 
Ken
|
|
4/7/2008 10:03:46 AM
|
dgraper Posts 4
|
Here's the single line answer (given to me by Martin Honnen, XML MVP):
clrs.AddRange(System.Enum.GetValues(typeof(System.Drawing.KnownColor)).Cast<System.Drawing.KnownColor>());
I was sort-of on the right track. This casting feature is unique to NET3.5, he said (complete post in the Microsoft.Public.DotNet.Languages.CSharp newgroup).
I'm coming from a NET2.0 background so this was new to me, that's what threw me.
|
|
4/7/2008 7:52:02 AM
|
dgraper Posts 4
|
Greetings.
Thanks for the book ... I need a quick overview of this topic and this book absolutely fits the bill.
I'm an ex-VB coder with a new job in an all-C# shop and am going thru the book translating the examples into C#. So far only one problem, pg. 70:
Dim enClr As System.Drawing.KnownColor Dim clrs As New System.Collections.Generic.List (Of System.Drawing.KnownColor) clrs.AddRange(System.Enum.GetValues (enClr.GetType()))
This seemed like an easy translation into C#:
System.Drawing.KnownColor enClr; System.Collections.Generic.List<System.Drawing.KnownColor> clrs = new System.Collections.Generic.List<System.Drawing.KnownColor>(); clrs.AddRange(System.Enum.GetValues(enClr.GetType()));
But I can't seem to get past an error in line 3 ("clrs.AddRange..."):
"Argument '1': cannot convert from 'System.Array' to 'System.Collections.Generic.IEnumerable<System.Drawing.KnownColor>'
It would seem that System.Enum.GetValues(enClr.GetType())) is returning a generic list of color objects but the AddRange method isn't accepting it.
Normally I'd try and cast the object into the format expected by the method but I know you can't do that with generics. Can anyone post the correct code snippet? TIA. - Dave Graper, Albany NY
|
|
pages:
1 |