Solved

C# class property update

Posted on 2016-08-14
5
67 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 62

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Calling web service and its methods dynamically 2 43
Needing an event fired when a row is added on a datagridview 4 37
Runtime Error 2 29
SQL syntax in VB.net 5 30
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

863 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now