Solved

C# class property update

Posted on 2016-08-14
5
61 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 78

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 32

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Converting C# Objects into JSON file 7 40
Need to Modify a Script I found 5 77
Check my code out(2) 1 33
Achieve json result 2 34
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

759 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

20 Experts available now in Live!

Get 1:1 Help Now