Solved

C# class property update

Posted on 2016-08-14
5
73 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
5 Comments
 
LVL 79

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 63

Assisted Solution

by:Fernando Soto
Fernando Soto earned 250 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 33

Accepted Solution

by:
it_saige earned 250 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

825 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