-
Junior Member
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());
}
-
Junior Member
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.
-
Expert Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules