Okies , i search for some code reference today, and accidentally found issues about type conversion in .net
There 3 types of cast , and based from what i read , i'll try to share it here.
CType - I think this is the commonly used in converting type. In our project, CType is mostly used in casting object from FindControl to the original type or from session to object such as dataTable. It need 2 parameter , the object and the new type. This function is included in .net by using Visual Basic namespace. Just as i mention before , this is maybe the most commonly used for type conversion because it is not strict. You can cast an object from string to integer, as long it have a valid value , such as "1234"
DirectCast - Using DirectCast , you can only convert a type to another type that has inheritance or implementation relationship. I can't really explain this , but from what i read, using directCast for a double to integer ,will throw an exception because there are no relationship. But we can cast System.Windows.Forms.Form to System.Windows.Forms.Control. We can see that , both of this type inherit from the FORMS. Benefit of using this compare to CType is better perfomance because it doesn't rely on Visual Basic routine.
TryCast - This one is quite interesting to me, because CType , DirectCast will throw an exception when it fail to convert type. But, by using TryCast , we will get NOTHING. So , why do you want to write codes for handle exception when TryCast can handle it for you? Ok, we got NOTHING, proceed to the next code. Yeah, thats cool. But theres a limitation here, you can only convert reference types, such as classes and interfaces and it have the same condition as DirectCast , from and to types that have relationship.
So, which one to use? Depends , but i think most of the time , it would be better if we use DirectCast , speed wise and we'll be more careful when declaring objects (If you know your variables have a value of "1234" , why declare it as a string , use integer instead (from here we should go deep , is it Int16,Int32 or Int64?))
Ok then , if you mind , please leave some comment , and if there any mistake in my post (and my english), please correct me
Thanks for reading this
CType | DirectCast | TryCast
Dicatat oleh nagakeciks di 4:35 PTG 6 ulasan
Label: CType, DirectCast, TryCast
Say HOLLA to Phase 2...
Yeah , Phase 2 is coming , Project Director came to our cabin this morning , show his new plan for phase 2.
Just like phase 1, my role in this project still as a QA + handles all Coding & UI standard. But without handling any module , so i can give 100% focus for my role this time. This percent means that , i'll be more strict & cruel (i'm not a dictator, it just my role!)
Lots of question about standards need to be answered , so i really hope that i'll get my streamyx as soon as possible. You ask today & you'll get the complete answer tomorrow (if i'm not busy playing online games)
In phase 2, each programmer must submit their UI & codes for my evaluation. For UI's evaluation, only screen that follow the standard & doesn't took to much time for loading will get my approval. For codes , programmer must make sure they follow the coding standard , using object type correctly , bugs-free , etc
Yeah , Fiza still the team leader. She has done a good job in phase 1, i'm sure she will do great in phase 2.
Good luck to team leader, me , & all programmers
Bored...
Waa,i'm totally bored right now.take my wife to see wak siah,for massage.lil bit sleepy,watch bored man u game,torrent the simpson,huaa.
ok,gtg.oh yeah,i post this using my n73.

