I tried to assign a value in aspx.cs file .
static String cnn;
cnn = "hi";
I get an error 'cnn is a field but used as a type'. I have added the code above all functions in the class.(not inside page load or any other event handler).
Why do I get this error and what is the reason ? How to fix ?
You can't refer to cnn
outside of a function, except when declaring the field.
If you want to declare and initialize the field, this can be done in one line:
static string cnn = "hi";
Note on style - in C#, use string
, not String
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.