Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8201739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:54:59+00:00 2026-06-07T06:54:59+00:00

I have class named config that have private string variable named param. I need

  • 0

I have class named “config” that have private string variable named “param”.

I need to get from “config” class “param” variable sometimes as int type sometimes as bool type or string.

As I understand I need create 3 properties in config class,each property have to convert type, as follow:

The first property converts string to int, the second converts string to bool, the third property gets me the string value.

The class should look something like this:

class Config
{
    private string param; 

   public int ParamAsInt
  {
    get 
    { 
        return int.Parse(param); 
    }
  }

  public bool ParamAsBool
  {
    get 
    { 
        return bool.Parse(param); 
    }
  }

  public string ParamAsString
  {
    get 
    { 
        return param; 
    }
  }

}

But I don’t know how can those properties be used in accordance to the variable type that I want to get out of class.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T06:55:00+00:00Added an answer on June 7, 2026 at 6:55 am

    This code won’t compile – int and such are reserved keywords and cannot be used as identifiers. You can either try naming your properties something like Int32Value, StringValue, etc., or try this:

    public static implicit operator bool (Config config)
    {
        return bool.Parse(config.param);
    }
    
    public static implicit operator int (Config config)
    {
        return int.Parse(config.param);
    }
    

    This will allow for much cleaner code:

    Config c = GetConfig("foo");
    var isFeatureEnabled = false || c;
    var spacing = 23 + GetConfig("bar");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Class named Constants that contains all the constant variable in my
I have a class named CropImageView which is extended from ImageView . but the
I have a class named baseClass. From this class I inherit a class names
I have a class named toto which I send to a function that does
I have something like that: faces-config.xml <managed-bean> <managed-bean-name>aBean</managed-bean-name> <managed-bean-class>some.pack.Bean</managed-bean-class> <managed-bean-scope>session</managed-bean-scope> </managed-bean> I have a
I have a class that uses a method from a bean. I'm trying to
i have class named Group i tried to test configuration: var cfg = new
I have a Class named Question and a related Class named Answers. I want
I have a class named FirstViewController which is a subclass of UIViewController and I
I have a class named Person and in this class is the property PersonName

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.