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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:27:47+00:00 2026-05-25T01:27:47+00:00

public class Teams : INotifyPropertyChanged { public string CombinedTeams { get { return Combined;

  • 0
public class Teams : INotifyPropertyChanged
    {
        public string CombinedTeams
        {
            get
            {                   
                return Combined;
            }

            set
            {                    
                {                                               
                    CombinedTeams += value;
                    NotifiyPropertyChanged("Combined"); 
                }
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        private void NotifiyPropertyChanged(string p)
        {
            if (null != p)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(p));
            }
        }
        private string Combined
        {

            get
            {
                return " " + HomeTeam + " " + HomeScore + " - " + AwayScore + " " + AwayTeam;
            }
            set 
            {
                { 
                    Combined += value;
                }
            }
        }
        public string HomeTeam { get; set; }
        public string AwayTeam { get; set; }
        public string HomeScore { get; set; }
        public string AwayScore { get; set; }
    }

I got a problem, when trying combine my strings together and having one LONG string that contains all the values from when I parse my XML I only get the First set of values,

basically I get

Team1 Score1 : Score2 Team2

as opposed to
Team1 Score1 : Score2 Team2 Team3 Score3 : Score4 Team4 Team5 Score5 : Score6 Team6

I am binding my Control to CombinedTeams

could you guys help me out? I just want to store the previous string and then combine the new string with the old one, I cant see it being hard but this is confusing me and reading up on it makes me more confused…

Thanks,

John

  • 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-25T01:27:48+00:00Added an answer on May 25, 2026 at 1:27 am

    The reason you are getting the incorrect results is because you have one property referring to another property, and the second property always returns a specific value.

    This block of code, when called from elsewhere, will return the results of some other variable called “Combined” which you have defined below…

    public string CombinedTeams                      
    {                      
        get                      
        {                                         
            return Combined;                      
        }                      
        ...
    }           
    
    private string Combined                        
    {                        
        get                        
        {                        
            return " " + HomeTeam + " " + HomeScore + " - " + AwayScore + " " + AwayTeam;                        
        }
        ...
    }
    

    Everything else is academic because you’re getter(s) essentially always return ” ” + HomeTeam + ” ” + HomeScore + ” – ” + AwayScore + ” ” + AwayTeam.

    I suspect you will want to restructure your code to be something more like this

    public class Teams : INotifyPropertyChanged
    {
        private string Combined; // Backing for CombinedTeams
        public string CombinedTeams
        {
            get
            {
                return Combined;
            }
            set
            {
                // This only concatinates values; Combined will get longer each time.
                Combined += value;
                // ViewModels should always notify after the vale has changed
                NotifyOfPropertyChange("CombinedTeams");
            }
        }
    
        // Adds a new team, assuming HomeTeam, HomeScore, AwayScore, and AwayTeam have been initialized
        public void AddTeam()
        {
            CombinedTeams = " " + HomeTeam + " " + HomeScore + " - " + AwayScore + " " + AwayTeam;              
        }                     
    }
    

    Certainly there are better ways to do that, but that should get you a start, I hope.

    General rule (broken all the time by the code-ninjas, which is fine) is that a Property shouldn’t do any calculations of it’s own, it’s really there to allow public access to private data in the class.

    It might be worthwhile to run through a couple of articles on C# Properties. Here are some suggestions to get you started: http://msdn.microsoft.com/en-us/library/x9fsa0sw(v=vs.80).aspx and http://msdn.microsoft.com/en-us/library/aa288470(v=vs.71).aspx and of course, some Good Search Results

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

Sidebar

Related Questions

public class Address { public string ZipCode {get; set;} } public class Customer {
I have a class like this: public class Contest { List<ContestTeam> Teams { get;
public class Test { public static void main(String[] args) { } } class Outer
public class doublePrecision { public static void main(String[] args) { double total = 0;
public class CovariantTest { public A getObj() { return new A(); } public static
public class WrapperTest { public static void main(String[] args) { Integer i = 100;
public class Main3 { public static void main(String[] args) { Integer min = Integer.MIN_VALUE;
public class abc1 { private String s; public abc1(String s){this.s=s;} public static void main(String
public class URLReader { public static byte[] read(String from, String to, String string){ try
If I set a value of an attribute of a class and use final,

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.