Below is the code to use instance of a class to be used in switch case
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;
namespace EnumFormApplication
{
public partial class Form1 : Form
{
enum date
{
sat,
sun,
mon,
tue,
wed,
thu,
fri,
};
public Form1()
{
InitializeComponent();
comboBox1.Items.Add(date.sun);
comboBox1.Items.Add(date.mon);
comboBox1.Items.Add(date.tue);
comboBox1.Items.Add(date.wed);
comboBox1.Items.Add(date.thu);
comboBox1.Items.Add(date.fri);
comboBox1.Items.Add(date.sat);
comboBox1.SelectedIndex = 1;
this.comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
}
bool IsHoliday(date date)
{
switch (date)
{
case date.sun:
case date.sat:
{
return true;
}
default:
{
return false;
}
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
date obj = (date)comboBox1.SelectedItem;
if (IsHoliday(obj))
{
textBox1.Text = "holiday";
}
else
{
textBox1.Text = "workingday";
}
}
}
}
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;
namespace EnumFormApplication
{
public partial class Form1 : Form
{
enum date
{
sat,
sun,
mon,
tue,
wed,
thu,
fri,
};
public Form1()
{
InitializeComponent();
comboBox1.Items.Add(date.sun);
comboBox1.Items.Add(date.mon);
comboBox1.Items.Add(date.tue);
comboBox1.Items.Add(date.wed);
comboBox1.Items.Add(date.thu);
comboBox1.Items.Add(date.fri);
comboBox1.Items.Add(date.sat);
comboBox1.SelectedIndex = 1;
this.comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
}
bool IsHoliday(date date)
{
switch (date)
{
case date.sun:
case date.sat:
{
return true;
}
default:
{
return false;
}
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
date obj = (date)comboBox1.SelectedItem;
if (IsHoliday(obj))
{
textBox1.Text = "holiday";
}
else
{
textBox1.Text = "workingday";
}
}
}
}