Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using ToString in VB.NET code in ASP.NET Web Page
Message
 
 
To
18/11/2009 02:37:24
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
ASP.NET
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01435079
Message ID:
01435381
Views:
37
>I see the young chicken has been helped by Viv
>
>The best way to learn is to make a class (or struct) for eg complex. Then implement the operators + - / *
>
>Then if you want to be able to write something like
>
>Complex c = new Complex(1,2);
>
>c = c + 2;  //  2 is an int
>
>If you want the above operation to succeed you'll have to define an 'implicit cast' in your complex type
>Then the compiler will first convert/cast 2 into/to complex(2,0), and then use the result of that to do the addition
>
>eg
>
>// this tells the compiler that there's an implicit  conversion/cast from an int to a complex possible
>//  (this is done when there's no loss of precision)
>public static implicit operator Complex(int i)
>{
>   return new Complex(i, 0);
>}
>
>
>
>Explicit operators define conversions that have to be cast, like
>
>double d = 1.5;
>int i = (int) d;
>
>int j = d; // will give an error
>
>
>but this will work
>
>d = 3;
>d = i;
>
>
>If you come across the term 'widening' in C#, then it means an implicit cast

Thanks. Can you post an example from your class with other operators (+,-, etc.) defined to complete the lesson? And please give a link (and if possible in VB.NET as well - since I may work with it too).

Thanks again.
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform