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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:30:18+00:00 2026-05-13T22:30:18+00:00

I was working on a public comments part of an application on Friday when

  • 0

I was working on a public comments part of an application on Friday when I got a stack overflow error, which confused me so I thought I’d ask for help. And searching the web using the expression ‘stack overflow’ is a bit self-defeating!

I wanted to do an HtmlEncode on the set statement of the field in the class, before sending an instance of the class to be added to the database:

public class Feedback
{

    public Feedback() { }

    public string FeedbackComment
    {
        get { return FeedbackComment; }
        set {System.Web.HttpUtility.HtmlEncode(value); }
    }

    // other fields 

    // methods
}

This was causing StackOverflow errors, I’ve fixed the error by changing the code to look like this:

public class Feedback
{

    public Feedback() { }

    private string feedbackComment;

    public string FeedbackComment
    {
        get { return feedbackComment; }
        set { feedbackComment = System.Web.HttpUtility.HtmlEncode(value); }
    }

    // other fields 

    // methods
} 

But I just wanted an explanation of why the first get/set statements were so recursive that they caused a stack overflow but when reverting the code to look more like c#2.0 worked? Can this be achieved with the shorter syntax and if so how?

This is my first question on SO – please try to be gentle!

  • 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-13T22:30:18+00:00Added an answer on May 13, 2026 at 10:30 pm

    The getter of the first example is returning the property itself, not a backing field.

    // The property name is "FeedbackComment"
    public string FeedbackComment
    {
        // And here you are returning "FeedbackComment" which is
        // creating the stack overflow
        get { return FeedbackComment; }
    }
    

    Unfortunately there is no way to shorten what you have, automatically implemented properties (i.e. public String FeedbackComment { get; set; }) must have empty getter and setter blocks to be syntactically correct. There is nothing wrong with your second example – yes, it is a bit verbose but it is clear, concise, and gets the job done.

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

Sidebar

Related Questions

This is the code for my array (which is working) Public numUsers As Integer
At the moment, I've got working: public void logowanie() { int x=5,y=5; ... }
I had this, which was working fine: public static Integer[] photos = new Integer[]
I'm working on my first ASP.NET MVC 3 application and I've got two Controllers
I'm working on a public-facing web project that will be powered in part by
Here's the generic class I'm working with: public interface IRepository<T> where T : EntityObject
I am working on a public facing MOSS 2007 site that uses the ViewFormPagesLockDown
I'm working on a public release if a model using Fortran 9x and I'd
I'm working on the following LINQ query: public void GetAuditRuleAgencyRecords(IEnumerable<Entities.AuditRule> rules) { using (LinqModelDataContext
I'm working on a site that pulls various public RSS feeds down. I want

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.