Example :
In this example, we see an enum type that indicates the importance of something. An enum type internally contains an enumerator list. We use enums when we want readable code that uses constants.
An enum type is a distinct value type that declares a set of named constants.
Karachi ., sindh @ Pakistan (Sarib;)
Programming :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
enum food
{
snacks,
coldrinks,
candies
};
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string a;
string b;
b = "I don't want";
a = "Want this";
food value = food.snacks;
if (value == food.snacks)
{
MessageBox.Show(b);
}
else if (value == food.candies)
{
MessageBox.Show(a);
}
}
}
}
Result :
Show "I don't want" on messagebox or dialog box.
No comments:
Post a Comment