asp.net Using StringBuilder

Soldato
Joined
12 Jan 2004
Posts
6,824
Location
Londinium
Hi guys,

Ive created a user control ascx page and I want to use the StringBuilder class as follows:

Code:
<script language="C#" runat="server">
	// Initialise variables
	public String Environment = "Dev";
	public String Version = "0.1";
	protected StringBuilder envVer = new StringBuilder();
	public String Content = "";
	
	// Create environment title string
	envVer.Append(Environment);
	envVer.Append(" ");
	envVer.Append(Version);
</script>

However, when I run the main page that uses this user control I get this error pointing to the code "envVer.Append(Environment);":

Code:
Compilation Error 

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 

Compiler Error Message: CS1519: Invalid token '(' in class, struct, or interface member declaration

I don't understand what Im doing wrong? Can someone please help?
 
Right, without seeing the whole thing it's hard to be sure, but:

1) Access modifiers are for use within classes, from the looks of it you're writing this code inline (take away the public/private/protected)

2) Enviroment is a .NET class. That should cause problems trying to declare your string if the rest of the script was ok.

They're the major problems I see ;)
 
Mickey said:
Right, without seeing the whole thing it's hard to be sure, but:

1) Access modifiers are for use within classes, from the looks of it you're writing this code inline (take away the public/private/protected)

2) Enviroment is a .NET class. That should cause problems trying to declare your string if the rest of the script was ok.

They're the major problems I see ;)

Thanks Mickey, it seems 1) was the problem! :)
 
Back
Top Bottom