Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Identifier expected error

Posted on 2006-05-23
5
Medium Priority
?
3,577 Views
Last Modified: 2012-05-05
I can't compile a program - it keeps saying identifier expected. This is my code:

namespace CircuitTRK {
   public struct UserStruct
   {

       public static string firstname;
       public static string lastname;
       public static string username;
       public static bool logout;

       public UserStruct(firstname, lastname, username, logout)
       {
         this.firstname = firstname;
         this.lastname = lastname;
         this.username = username;
         this.logout = logout;
       }

   }

}
0
Comment
Question by:jeremyduj
5 Comments
 
LVL 44

Expert Comment

by:bruintje
ID: 16746871
Hi jeremyduj,
----------

not sure if i understand what you are trying to do but you could read up on structs in C# here
source: http://www.c-sharpcorner.com/Language/StructuresInCSRVS.asp

if i'm correctly interpreting you need to write it like

namespace CircuitTRK {

   public struct UserStruct
   {
       public string firstname;
       public string lastname;
       public string username;
       public bool logout;
   }

// use it in a class like
   class MyClient
   {
            public static void Main()
            {
                        MyStruct ms = new UserStruct();
                        ms.firstname = "first";
                        ms.lastname = "last";
                        ms.username = "lastfirst";
                        ms.logout = false;
                        // rest of code
              }
   }
}

but i could be wrong just comment if so

----------
bruintje
share what you know, learn what you don't
0
 
LVL 25

Accepted Solution

by:
dstanley9 earned 500 total points
ID: 16746936
You need to add types to your cunstructor parameters:

       public UserStruct(string firstname, string lastname, string username, string logout)
       {
         this.firstname = firstname;
         this.lastname = lastname;
         this.username = username;
         this.logout = logout;
       }
0
 
LVL 6

Expert Comment

by:PoeticAudio
ID: 16746987
public UserStruct(firstname, lastname, username, logout)
       {
         this.firstname = firstname;
         this.lastname = lastname;
         this.username = username;
         this.logout = logout;
       }

This is your problem. You are saying "this" when "this" represents an instance of the class whereas static variables are classifier variables (ie apply to all instances, stored at the class level not the instance level)

Are you sure that you want to use static variables? Whenever you create instances of this, all instances will have the same firstname, lastname, username...etc because those variables are static. So if you create an instance with the name "john" then all instances of that struct will have the name "john" because firstname is static.

If that's what you're after then you will have to do something like:

public struct UserStruct
   {

       public static string user_firstname;
       public static string user_lastname;
       public static string user_username;
       public static bool user_logout;

       public UserStruct(firstname, lastname, username, logout)
       {
         user_firstname= firstname;
         user_lastname= lastname;
         user_username= username;
         user_logout= logout;
       }

   }



0
 
LVL 6

Expert Comment

by:PoeticAudio
ID: 16747002
Sorry, this would be the correct implementation. (you didn't specify the types in your constructor either, which is another problem)

public struct UserStruct
   {

       public static string user_firstname;
       public static string user_lastname;
       public static string user_username;
       public static bool user_logout;

       public UserStruct(string firstname, string lastname, string username, bool logout)
       {
         user_firstname= firstname;
         user_lastname= lastname;
         user_username= username;
         user_logout= logout;
       }

   }
0
 
LVL 4

Expert Comment

by:garima_sikarwar
ID: 16749670
You should Use

public struct UserStruct
{
public static string str_firstname;
public static string str_lastname;
public static string str_username;
public static bool str_logout;

public UserStruct(string firstname,string lastname,string username,bool logout)
{
str_firstname = firstname;
str_lastname = lastname;
str_username = username;
str_logout = logout;
}
}

this is related to an instance of class and static variables are shared among all the instances of class..


0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

577 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