Hi all
Look that sub in the class
C# Code:
class cone { float ht, rd; public void set(float h, float r) { ht = h; rd = r; } }
C# Code:
cone c1; c1=new cone(); c1.set(12.34,23.0);
ERROR HERE c1.set(12.34,23.0);
CAN NOT CONVERT DOUBLE TO FLOAT. WHY??
Printable View
Hi all
Look that sub in the class
C# Code:
class cone { float ht, rd; public void set(float h, float r) { ht = h; rd = r; } }
C# Code:
cone c1; c1=new cone(); c1.set(12.34,23.0);
ERROR HERE c1.set(12.34,23.0);
CAN NOT CONVERT DOUBLE TO FLOAT. WHY??
"float" is an alias for Single. If you don't specify otherwise, any literal number with a decimal point in it is a Double. You cannot implicitly convert a Double to a Single because it is a narrowing conversion, i.e. data could be lost. If your method is expecting floats then you need to pass floats to it. To force a literal to type float you use an "F" suffix:C# Code:
c1.set(12.34f, 23.0f);
Thanks sir :wave:Quote:
Originally Posted by jmcilhinney
It's working fine now.Can you give the list of more suffix in C# , that we have need to use in the code.
What did your last slave die of? ;) Look it up on MSDN, as you should ALWAYS do first. I think I may have mentioned that once or twice. Someone will take notice one day.
Today:bigyello:Quote:
Originally Posted by jmcilhinney
Thanks sir