Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

c#.net - setting a value to a variable---does a missing bracket cause this error?

Posted on 2011-09-25
4
Medium Priority
?
162 Views
Last Modified: 2013-12-17
I get this error, maybe the braces are not matched up:

    string new_time_sent_range = null;

    new_time_sent_range = "l";

invalid token '=' in class, struct, or interface declaration
0
Comment
Question by:GlobaLevel
  • 2
4 Comments
 
LVL 7

Accepted Solution

by:
Bill Nolan earned 2000 total points
ID: 36596511
Your error is elsewhere.  Check the integrity of your class (esp. mismatched braces, missing semicolon, etc.)
0
 
LVL 14

Expert Comment

by:binaryevo
ID: 36596527
I concur with Slimfinger.  The code you provided looks fine...
0
 
LVL 12

Expert Comment

by:rajapandian_81
ID: 36597195
Hi,

You can not assign values to variable in class level. You can do only declaration. Modify the code like below:
    public partial class Form1 : Form
    {
        string new_time_sent_range = null;        

        public Form1()
        {
            InitializeComponent();
            new_time_sent_range = "l";

Open in new window

0
 
LVL 7

Expert Comment

by:Bill Nolan
ID: 36597427
Note: you can assign values at class level, but only in the initializer, such as:

string new_time_sent_range = "l";

0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question