What is the need for typecasting
hello friends,
Actually enum contains a collection of integer constants.
In button1_click i declared i as an integer only then what is the need for typecasting?
enum gtb
{
sa=12
}
private void button1_Click(object sender, EventArgs e)
{
int i;
// i = gtb.sa;
i=(int)gtb.sa ;
MessageBox.Show(i.ToString());
}
Re: What is the need for typecasting
Hi,
enum gtb
{
sa=12
}
private void button1_Click(object sender, EventArgs e)
{
int i;
// i = gtb.sa;
i=(int)gtb.sa ;
MessageBox.Show(i.ToString());
}
Here if u use like gtb.sa then u r trying to access the member name not the value. and in c# it takes everything like string that is the need we need to convert externally,so we need TypeCasting,if u want to get integer value u need to convert externally.
Re: What is the need for typecasting
If you need the value from the enum then you have to type cast else enum will return the only name