code_junkie

Why does (string)int32 always throw: Cannot convert type 'int' to 'string'

Nov 13th, 2011
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. public class Foo
  2. {
  3. private int FooID;
  4. public Foo()
  5. {
  6. FooID = 4;
  7. string s = (string)FooID; //throws compile error
  8. string sss = FooID.ToString(); //no compile error
  9. }
  10. }
  11.  
  12. string s = (string)70;
  13.  
  14. string s = Convert.ToString(-70, 10);
  15.  
  16. string s2 = 70.ToString("D");
  17.  
  18. int test1 = 34;
  19. double test2 = (double)test1;
  20.  
  21. int test1 = 34;
  22. string test2 = (string)test1;
Add Comment
Please, Sign In to add comment