TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Maha
NA
600
70.8k
Switch statement
Oct 21 2014 11:58 AM
http://www.dotnetperls.com/switch
In the above webpage under the CAUTION heading it says that expression in the switch must be
int/char/string
.
In the following program different type is used in the switch expression. Could you explain the difference please? Problem is highlighted.
using System;
enum Priority
{ Zero, Low, Medium, Important, Critical }
class Program
{
static void Main()
{
// New local variable of the Priority enum type.
Priority priority = Priority.Zero;
// Set priority to critical on Monday.
if (DateTime.Today.DayOfWeek == DayOfWeek.Monday)
priority = Priority.Critical;
// Write this if the priority is important.
if (IsImportant(priority))
Console.WriteLine("The problem is important.");
// See if Low priority is important.
priority = Priority.Low;
Console.WriteLine(IsImportant(priority));
// See if Important priority is.
priority = Priority.Important;
Console.WriteLine(IsImportant(priority));
Console.ReadKey();
}
static bool IsImportant(Priority priority)
{
// Switch on the Priority enum.
switch (
priority
)
{
case Priority.Low:
case Priority.Medium:
case Priority.Zero:
default:
return false;
case Priority.Important:
case Priority.Critical:
return true;
}
}
}
Reply
Answers (
10
)
convert record into column header
Displaying text file to Windows Application