Link to home
Start Free TrialLog in
Avatar of mathieu_cupryk
mathieu_cuprykFlag for Canada

asked on

Initialize an object?

I need to create a class for a simobject
public struct SIMObject
    {
        public int SimID = string.Empty;
        public string SimNumber = string.Empty;
        public string Msisdn = string.Empty;
        public string Imsi = string.Empty;
        public string Status = string.Empty;
        public string Profile = string.Empty;
        public string ActivationDate = string.Empty;
    }
How should I setup the above object?

Open in new window

Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

I'm not quite sure what you are getting at. What is wrong with your struct declaration as it is?
Avatar of sunithnair
sunithnair

Did you mean how to intialize stuct object?
SIMObject obj = new SIMObject();

Open in new window

Avatar of mathieu_cupryk

ASKER

Error      1      'SIMObject': member names cannot be the same as their enclosing type      W:\webs\CarrierStubs\App_Code\PCM\SIMObject.cs      16      19      W:\webs\CarrierStubs\
Are you having this struct inside the class with the same name as the struct? Either rename the struct or the class..
SIMObject.cs contains a class named SIMObject inside which you are defining the struct. You can also fully remove the class and have just the struct in the SIMObject.cs file
Can you please show me how I should set this up?
Error      7      'PCM.SIMObject.SimID': cannot have instance field initializers in structs      W:\webs\CarrierStubs\App_Code\PCM\SIMObject.cs      15      20      W:\webs\CarrierStubs\
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace PCM
{
    public struct SIMObject
    {
        public int SimID = string.Empty;
        public string SimNumber = string.Empty;
        public string Msisdn = string.Empty;
        public string Imsi = string.Empty;
        public string Status = string.Empty;
        public string Profile = string.Empty;
        public string ActivationDate = string.Empty;
    }
   
}
ASKER CERTIFIED SOLUTION
Avatar of sunithnair
sunithnair

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
where is your bracket?
i get compilation error.