Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

C# class property update

Posted on 2016-08-14
5
Medium Priority
?
81 Views
Last Modified: 2016-08-30
Hi

I have below class

public string CallTime
    {
        public String QStateCode { get; set; }
        public int   CallID {get;set}
       
}

I get QStateCode as from service call. The  value is for e.g is  "072 - San Francisco"

I need QStateCode = "072" to be displayed to the UI. So I need send it to UI.  How do I achieve this.

Thanks
Adib
0
Comment
Question by:Member_2_7967608
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 83

Expert Comment

by:David Johnson, CD, MVP
ID: 41755776
label1.text = Calltime();  //immediately comes to mind.
0
 

Author Comment

by:Member_2_7967608
ID: 41755839
Sorry I did an error. Its a class
public class CallTime
    {
        public String QStateCode { get; set; }
        public int   CallID {get;set}
    }
The web service populates instance of this class. I want to bind the instance to the UI. But the sevice populates
QStateCode = "072 - San Francisco".  I want to write some clean code to make the value ="072". should I create a new property.
0
 
LVL 64

Assisted Solution

by:Fernando Soto
Fernando Soto earned 1000 total points
ID: 41755897
Hi;

Make your class like this which is all that is needed.
public class CallTime
{
    private String qStateCode; 
    public String QStateCode 
    {
        get { return qStateCode; }
        set 
        {
            int index = value.IndexOf(' ');
            qStateCode = value.Substring(0, index);
        }
    }
    public int CallID { get; set; }
}

Open in new window

0
 
LVL 34

Accepted Solution

by:
it_saige earned 1000 total points
ID: 41756770
Along with what Fernando has stated, if you do not wish to loose the name portion of the code, you could add an additional property with which to place the information; e.g. -
public class CallTime
{
	private string qStateCode;
	private string qStateName;

	public string QStateCode
	{
		get { return qStateCode; }
		set
		{
			if (!string.IsNullOrEmpty(value))
			{
				var pair = value.Split('-');
				if (!string.IsNullOrEmpty(pair[0]))
					qStateCode = pair[0].Trim();

				if (pair.Count() > 1 && !string.IsNullOrEmpty(pair[1]))
					qStateName = pair[1].Trim();
			}
		}
	}

	public string QStateName
	{
		get { return qStateName; }
	}

	public int CallID { get; set; }
}

Open in new window


-saige-
0
 

Author Closing Comment

by:Member_2_7967608
ID: 41777382
Thanks . I was able to get it working
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

661 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question