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 7995969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:34:43+00:00 2026-06-04T14:34:43+00:00

I am trying to define a property inside the main class in my Windows

  • 0

I am trying to define a property inside the main class in my Windows Service. The property will be used to retrieve the name of the process whenever required.

For eg:

public string PName
{
return SomeProcess.Name;
}

public string PID
{
return SomeProcess.ProcessId;
}

public Process SomeProcess
{
private Process[] myProcess = Process.GetProcessesByName("notepad"); //Process is underlined here with red wavy line saying "A get or set accessor method is expected"
get
{return myProcess[0];}
}

The problem is inside the SomeProcess property written in the comment. What am I doing wrong here?

  • 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-04T14:34:45+00:00Added an answer on June 4, 2026 at 2:34 pm

    Make it like this:

    private Process[] myProcess = Process.GetProcessesByName("notepad"); 
    public Process SomeProcess
    {
       get
       {
            return myProcess[0];
       }
    }
    

    or

    public Process SomeProcess
    {
       get
       {
            Process[] myProcess = Process.GetProcessesByName("notepad"); 
            return myProcess[0];
       }
    }
    

    EDIT

    Note that you need to decide when you want to get the processes. If you do it as I showed in my first sample the process will be retrieved when the class is instantiated. The second way is more robust as it will retrieve the process when you ask for the value of the property.

    I stated both answers because you asked what the error means and is more about private and local variables.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to retrieve a custom Attribute set on a page's class from inside
I'm trying to create a point class which defines a property called coordinate. However,
I'm trying to define a delegate function that will return an IEnumerable. I'm having
I'm trying to define base class, which contains typedef's only. template<typename T> class A
I'm trying to define an object and create an accessor property for it. HTML:
I am trying to define all my main variables within an object called globals
I am trying to define simple getter/setter methods for a mixin class that I
I'm trying to define a class that, in its constructor, instantiates other objects and
Im trying to define a select tag in my view. My view looks like
I'm trying to define a new shortcode in WordPress, and I get the following

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.