Solved

C# class property update

Posted on 2016-08-14
5
79 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 82

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 34

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

Major Serverless Shift

Comparison of major players like AWS, Microsoft Azure, IBM Bluemix, and Google Cloud Platform

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
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…

615 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