Nicer way to validate a value type out of System.Data.DataRow
-
Hello everbody! Just looked threw my project and found code which I don't like at all. I'm having an instance of DataRow and go threw it in a loop. There I need to store the data for example in a double array. This is what I do now: if (myrow[x].GetType() == typeof(System.Double)) { doublearray[x]= (double)myrow[x]; } For reference types I would use the "as" operator! Is there a nicer way to do this? Thanks for suggestions! All the best, Martin
-
Hello everbody! Just looked threw my project and found code which I don't like at all. I'm having an instance of DataRow and go threw it in a loop. There I need to store the data for example in a double array. This is what I do now: if (myrow[x].GetType() == typeof(System.Double)) { doublearray[x]= (double)myrow[x]; } For reference types I would use the "as" operator! Is there a nicer way to do this? Thanks for suggestions! All the best, Martin
**is** System.Double)(I rarely useas
; I usually just cast.) -
**is** System.Double)(I rarely use
as
; I usually just cast.) -
Hello,
PIEBALDconsult wrote:
is System.Double)Does this compile? I thought it's (is and as) only working for reference type. All the best, Martin
I use it.
-
I use it.
-
Hello, Sorry! Just tested it and found out that is also works with valuy types, but as only works with reference types. All the best, Martin
It's better to try something even if you think it won't work.