|
-
Jun 13th, 2003, 05:05 PM
#1
Thread Starter
Member
Convert.ToXXXX(object) vs (XXX)object
What is more effecient to use when converting data types in C#.
Convert.ToXXXX(object) method or (XXXXX)object way?
-
Jun 13th, 2003, 06:38 PM
#2
i find the Convert.To method the best
eg:
Code:
string str="i'm some text " + Convert.ToChar(169);///169 is copyright symbol
MessageBox.Show(str);
in this example you can see another use of Convert , calculating time span differences :
Code:
private void button8_Click(object sender, System.EventArgs e)
{
try
{
string strDate="11/06/2003 10:20:15";
string strFinish="11/06/2003 18:28:37";
TimeSpan s=Convert.ToDateTime(strFinish).Subtract(Convert.ToDateTime(strDate));
MessageBox.Show("Difference in time:\n" + s.ToString());
}
catch
{
System.Exception f = new System.Exception();
MessageBox.Show(f.Message);
}
}
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
Jun 15th, 2003, 12:00 PM
#3
yay gay
Originally posted by dynamic_sysop
i find the Convert.To method the best
eg:
Code:
string str="i'm some text " + Convert.ToChar(169);///169 is copyright symbol
MessageBox.Show(str);
in this example you can see another use of Convert , calculating time span differences :
Code:
private void button8_Click(object sender, System.EventArgs e)
{
try
{
string strDate="11/06/2003 10:20:15";
string strFinish="11/06/2003 18:28:37";
TimeSpan s=Convert.ToDateTime(strFinish).Subtract(Convert.ToDateTime(strDate));
MessageBox.Show("Difference in time:\n" + s.ToString());
}
catch
{
System.Exception f = new System.Exception();
MessageBox.Show(f.Message);
}
}
for casting numbers to char i prefer a lot using (char)number as a char is just a kind of typedef of a ushort(from 0 to 65535 if i am not mistaken) so if u put a number from 0 to 65535(altough i think when using regular encoding you just use from 0 to 255) no error will happen and the code gets a lot easier to read from if u have many chars u want to convert
Last edited by PT Exorcist; Jun 15th, 2003 at 12:03 PM.
\m/  \m/
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|