(Brackets)

If this conversion is not possible then an exception is thrown.
This requires a cast operator and is also known as Casting.


int myint = 10; 
short myshort1 = (short)myint;

This is an example of a narrowing conversion


For classes an explicit conversion is needed to convert a base class to a derived class.

public class Base {} 
public class Derived : Base {}
Derived D = (Derived)(new Base());



© 2022 Better Solutions Limited. All Rights Reserved. © 2022 Better Solutions Limited TopPrevNext