int and Iconvertible interface

  • Thread starter Thread starter Rene
  • Start date Start date
R

Rene

According to the documentation, the int (Int32) type inherits the
Iconvertible interface. This interface has a bunch of methods such as
ToDecimal, ToDouble etc. The thing is that I don't seem to be able to see
any of this methods, even if I make a direct cast in the int. What am I
missing?



Thanks.
 
I don't get it, before I posted this I tryied doing this:

int someInt = 0;
IConvertible interfaceRef = (IConvertible)someInt;

Then I used the "interfaceRef " variable to get a hold of the methods on the
IConvertible interface but I only saw the same thing as if I was using the
"someInt" variable. If it works on your computer then something must be
wrong with my intellisense. Maybe a good reboot will fix the problem.

Thanks.
 
1) If you cast to Icomparable this should work,
2) The reason that you can't see these methods is because there is an
explicit interfact reference,
this is slightly different, have a look at this quick sample

interface I_Foo
{
void Bar();
}

public class Foo : I_Foo
{
#region I_Foo Members

public void Bar()
{
MessageBox.Show("hello");
}

#endregion

}

public class Foo2 : I_Foo
{
#region I_Foo Members

void I_Foo.Bar()
{
MessageBox.Show("I_Foo.Bar");
}

#endregion

}
 
avnrao said:
true. VS doesnt display all these methods in intellisense.
you can use explicit interface implementation by casting IConvertible
iconvertInt = (IConvertible)YourInt.
and then use methods.

this is because, these types are most frequently used and i guess VS team
considered not to display a deluge of methods in intellisense.
The best way to use is Convert class.

it's not an issue of intellisense not displaying it. when a method of the
interface is explicitly implemented, it's simply not available through the
type. that's a C# language feature, not a VS display feature.
 
Back
Top