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

  • SEARCH
  • Home
  • 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 225305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:24:01+00:00 2026-05-11T19:24:01+00:00

I have a class called ItemBase from which a number of classes inherit. In

  • 0

I have a class called ItemBase from which a number of classes inherit.

In this class I have a number of one-line methods which simply return a string or object and are available to all the inheriting classes. I use these quite a bit in inherited classes to make code more readable and so that I always have one and only one place that defines each calculation or piece of information.

I used Getters like I do in PHP and Java since this is the way I have always done it:

public class ItemBase
{
    protected string GetApplicationPath()
    {
        return System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase);
    }

    protected string GetApplicationDataPath()
    {
        return GetApplicationPath() + @"..\..\..\TestServices\";
    }
}

However, I’ve noticed that Getters and Setters aren’t really used in C# as they are in Java or PHP and and I suspect that there is a better, more succinct/standard way to do this in C#.

But I don’t want to use class variables since it doesn’t seem right to define logic in the a class variable initializer, I assume that even though possible for some calculations it is probably frowned upon and causes problems in some cases:

protected string _applicationPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase);

I stay away from public fields after reading about disadvantages you have with them down the road in Jon Skeet’s article. Plus this is too much code for just a simple definition.

protected string ApplicationPath
{
    get
    {
        return System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase);
    }
}

I could use C#’s abbreviated properties but then each little piece of information has code in two places and the name is used twice, just doesn’t seem like a succinct solution.

protected string ApplicationPath { get; set; }

public ItemBase()
{
    ApplicationPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase);
}

So I’ve settled on using these Getters just like I do in PHP and Java, although this doesn’t seem to be a very C# way to go about it.

What conventions do you use in C# for storing these “one-line class variables” that just hold a piece of information or do a little calculation?

ANSWER:

protected string ApplicationPath
{
    get { return System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase); }
}

protected string ApplicationDataPath
{
    get { return ApplicationPath + @"..\..\..\TestServices\"; }
}
  • 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-05-11T19:24:01+00:00Added an answer on May 11, 2026 at 7:24 pm

    “I could use C#’s abbreviated properties but then each little piece of information has code in two places and the name is used twice, just doesn’t seem like a succinct solution”

    What do you mean by that? Properties are just syntactic sugar for the getters / setter methods you would normally do in Java. Where do you see code in two places?

    public string MyProp
    {
       get{return "MyProp";}
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class called XMLtoXML.java and this is one of it's methods... import
I have a class called Path for which there are defined about 10 methods,
I have a class called RemoteError with a self.fatal method on it. This methods
I have one class called MainMenu, which has a method called switchViews, with 2
I have a class called IssuesView which implements INotifyPropertyChanged . This class holds an
I have a class called BaseB which can be called from A . I
I have a class called EventConsumer which defines an event EventConsumed and a method
I have a class called Ship and a class called Lifeboat Lifeboat inherits from
I have this class called Table: class Table { public string Name { get
i have this class called MemoryManager, it is supposed to implement a simple smart

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.