We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Initialize an object?

mathieu_cupryk
on
Medium Priority
216 Views
Last Modified: 2012-05-06
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

Comment
Watch Question

Carl TawnSenior Systems and Integration Developer
CERTIFIED EXPERT

Commented:
I'm not quite sure what you are getting at. What is wrong with your struct declaration as it is?
Did you mean how to intialize stuct object?
SIMObject obj = new SIMObject();

Open in new window

Author

Commented:
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

Author

Commented:
Can you please show me how I should set this up?

Author

Commented:
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;
    }
   
}
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;
        public string SimNumber;
        public string Msisdn;
        public string Imsi;
        public string Status;
        public string Profile;
        public string ActivationDate;
    public SIMObject
    {
        SimID = 0;
        SimNumber= string.Empty;
        Msisdn= string.Empty;
        Imsi= string.Empty;
        Status= string.Empty;
        Profile= string.Empty;
        ActivationDate= string.Empty;
    }
    }
}

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
where is your bracket?
i get compilation error.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.