Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
this is my output
C#
var response = Client.GetCrewLeaveWeeks(GetCrewLeaveWeeksReq.userId, GetCrewLeaveWeeksReq.password, GetCrewLeaveWeeksReq.depotKey, GetCrewLeaveWeeksReq.startDate,  GetCrewLeaveWeeksReq.endDate, GetCrewLeaveWeeksReq.linkId, GetCrewLeaveWeeksReq.leaveType);

txt_Results.Text = Convert.ToString(response);

I need it to return all of the getcrewleave requests into the text box named txt_Results but it just doesn't work at all, this is coming from a windows form which requires certain things to be entered then when you click submit it accesses a service reference

is this something that can be helped with this little information?

thanks :3

tell me if you need more!
Posted
Updated 17-Feb-14 23:18pm
v3
Comments
Krunal Rohit 17-Feb-14 11:13am    
And what are you getting as an output in TextBox ?
ZurdoDev 17-Feb-14 21:38pm    
Where are you stuck?
Member 10603307 18-Feb-14 4:11am    
It doesn't return what I need it to.

It just returns Test_Harness.CrewPlanInterface.CrewLeaveWeeks
ZurdoDev 18-Feb-14 6:54am    
Then perhaps GetCrewLeaveWeeks is not the right method. We have no idea what that method is or what it returns so you'll have to look into it.

1 solution

The string it returns: "Test_Harness.CrewPlanInterface.CrewLeaveWeeks" is the result of the default ToString implementation, inherited from object. When you create a class, if you do not create a specific implementation of ToString then anything which tries to convert an instance of your class to a string will return the name of the class (as in this case) instead of any content.

So what you need to do is something like this:
C#
public class MyClass
    {
    public int X { get; set; }
    public int Y { get; set; }
    public override string ToString()
        {
        return string.Format("({0},{1})", X, Y);
        }
    }
Now, when Tostring is called, it returns a string representation of the location coordinates. Since Convert.ToString calls ToString, it will also do the same thing.

It's a good idea to always create a ToString override for your own classes: if nothing else it's really handy for debugging! :laugh:
 
Share this answer
 
Comments
Member 10603307 18-Feb-14 6:01am    
Thanks, I don't suppose you could go into a little more detail about string overrides? Not really done them that much and struggling a bit here, does this go in the same class? What would it look like to show 7 outputs? Thanks :3
OriginalGriff 18-Feb-14 6:08am    
If you want a method in your class, then yes, it has to go in the class! :laugh:
Do you know what an override is yet? Or have they not covered that in your course?
The version I show gives two outputs: the X and Y properties - if you want more properties, then just extend the string.Format to cover the ones you want. But...ToString (and Convert.ToString) only returns a single string item - it can't return multiple objects. But then, a TextBox isn't good at multiple objects either! :laugh:
Member 10603307 18-Feb-14 6:18am    
Not really no, only briefly but nothing in this context D:

What property would I give it?
I appreciate the help, not really done much like this before >_<
OriginalGriff 18-Feb-14 6:29am    
OK: a (very) quick overview:
Override is a way to decide which method should be called at run time: if a class implements MethodX and you derive a class from it, your derived class can implement it's own version of MethodX by overriding it. The system then calls the appropriate version based on whether the object you called MethodX on is a base class instance or a derived class instance.

Object implements the ToString method, and returns the name of the class. If your class implements a "newer" version, then everything that tries to convert an instance of your class will call your version instead of the default object version.

Your version can return whatever it wants - as long as it's a string - it's just a case of looking at your class and deciding what part or parts of it are useful to return and making the string contain them. I can't tell you what properties to put in the string - because I have no idea what properties your class contains! :laugh:
But it doesn't have to be properties - it can be anything. Fixed strings, fields, method results, anything you want to show the user.
So for a User class, it might return
string.Format("User: {0}\nEmail: {1}\nAddress: {2}", userName, userEmail, GetAddress());

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900