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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:02:30+00:00 2026-06-17T20:02:30+00:00

An example has been shown to me today, and just wanted to check if

  • 0

An example has been shown to me today, and just wanted to check if both of the following will in fact have the same effect, and it not, what the difference is between them.

Is this:

private static Service1Client _myFoo;

static ServiceLayer()
{
    MyFoo = new Service1Client();
}

public static Service1Client MyFoo
{
    get { return _myFoo; }
    set { _myFoo = value; }
}

Just a long winded way of doing this:

public static Service1Client _myFoo
{
    get { return _myFoo; }
    set { _myFoo = value; }
}

static ServiceLayer()
{
    _myFoo = new Service1Client();
}

If this isn’t the case, what is the difference between them?

Thanks.

  • 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-17T20:02:32+00:00Added an answer on June 17, 2026 at 8:02 pm

    You need the backing field because:

    public static Service1Client _myFoo
    {
        get { return _myFoo; }
    }
    

    ….like you have in your example will loop forever.

    However, C# does provide automatic properties. You could accomplish the same thing with this simple code:

    public static Service1Client MyFoo { get; set; }
    
    static ServiceLayer()
    {
        MyFoo = new Service1Client();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is the hook_block has been changed? the following is drupal 6 example i have
How do I check if input has been entered? For example (python2) x =
I have been using Shawn Wildermuths example and it has been working fine no
This problem has been bugging me for a long time. For example, the code
Sorry if this has been asked before, but I couldn't find a good example
UPDATE 2011.09.13 This bug has been resolved by Adobe. The example code below now
I have 2 websites, lets say - example.com and example1.com example.com has a database
I have a table, an example shown below, that lists people and their birth
So I have an iterative closest point (ICP) algorithm that has been written and
i'm using the source code for multiple selection Dropdown check-list Since, the example has

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.