nebie problem with c# asp.net syntax....

D

DC

Why in the hell am i getting this error?

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

Source Error:

Line 5: <script runat="server">
Line 6:
Line 7: using System;
Line 8: using System.Collections;
Line 9: using System.IO;

The code isnt really importanat but try as I might the "using" keyword
is causing an error, is this common am I being incredbly stupid? Does
anyone have a good example of a very basic c# asp.net pagI can play with?

Never had this much hassle writing scripts in vbscript :)

Thanks in advance.

--
_______________________________________________

DC

"You can not reason a man out of a position he did not reach through reason"

"Don't use a big word where a diminutive one will suffice."

"A man with a watch knows what time it is. A man with two watches is
never sure." Segal's Law
 
B

Brock Allen

The problem is that code in the <script runat=server> goes in the class definition,
so:

<script runat=server>
void foo() {}
</script>

becomes

class YourPage : Page {
void foo() {}
....
}

So when you put the using starements in there it becomes:
class YourPage : Page {
using System;
void foo() {}
....
}

Which is illegal. You need the <%@ Import %> directive instead at the top
of the page:
<%@ Import Namespace="System"%>
<%@ Import Namespace="System.Collections"%>
etc...
 
D

DC

Cheers thats really helpful. Seems liek none of the examples ou there
are really designed to explain how to do things for a total newbie. They
all seem to be about principles rather than practicality.

Anyway thanks again,

Brock said:
The problem is that code in the <script runat=server> goes in the class
definition, so:

<script runat=server>
void foo() {}
</script>

becomes
class YourPage : Page {
void foo() {}
...
}

So when you put the using starements in there it becomes:
class YourPage : Page {
using System;
void foo() {}
...
}

Which is illegal. You need the <%@ Import %> directive instead at the
top of the page:
<%@ Import Namespace="System"%>
<%@ Import Namespace="System.Collections"%>
etc...

--
_______________________________________________

DC

"You can not reason a man out of a position he did not reach through reason"

"Don't use a big word where a diminutive one will suffice."

"A man with a watch knows what time it is. A man with two watches is
never sure." Segal's Law
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top