By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,686 Members | 2,770 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,686 IT Pros & Developers. It's quick & easy.

C# switch statement

P: n/a
Hi All... I am a beginning .NET developer and am using C# with ASP.NET. I am
having trouble with switch statements, can anyone help?

When I run the below code, I receive an error "Compiler Error Message:
CS1519: Invalid token 'switch' in class, struct, or interface member
declaration"

<%@ Page Language="C#" %>

<script runat="server">
void Page_Load(Object Sender, EventArgs e);
string FirstName = "David";

switch (FirstName) {
case "David":
Response.Write("David");
break;
case "Michael":
Response.Write("Michael");
break;
default:
Response.Write("Not David or Michael");
break;
}
}
</script>

<html><body>
</html></body>
Jul 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

"David Whitfield" <Da************@discussions.microsoft.com> wrote in
message news:84**********************************@microsof t.com...
Hi All... I am a beginning .NET developer and am using C# with ASP.NET. I
am
having trouble with switch statements, can anyone help?

When I run the below code, I receive an error "Compiler Error Message:
CS1519: Invalid token 'switch' in class, struct, or interface member
declaration"

<%@ Page Language="C#" %>

<script runat="server">
void Page_Load(Object Sender, EventArgs e);
Page_Load was ended by the ';'. so FirstName is a class-level variable, and
'switch' is in the class declaration, where it is invalid.

You really should use code-behind your C# code, so your IDE can help you
with the language. Integrating server-side source code in the .aspx file is
supported, but should generally be avoided.

string FirstName = "David";

switch (FirstName) {

.. . .

David
Jul 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.