Click here to Skip to main content
15,898,954 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi,

I am into one project in between. So i am new to .net and unable to find out what to return in hte code mentioned below. Any help would be appreciated:

doubt is after return keyword, what to retuen?


C#
List<string> int getupdatedetails(int id)
{
    string servername = string.Format("{0}.{1}", Environment.MachineName, System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().DomainName);
    var uri = new Uri(string.Format("http://{0}//relativity.services/", servername));
    
    using (ArtifactManagerProxy proxy = new ArtifactManagerProxy(uri))
    {
        string emailaddress="";
        var querys = new DTOs.Query<dtos.rdo>();
        querys.ArtifactTypeGuid = GUIDCollection.O_PERSON_GUID;
        DTOs.QueryResultSet<DTOs.RDO> results = proxy.Repositories.RDO.Query(querys)
        if (!results.Success)
        {
            Utils.WriteToLog(": query for Tasks failed: " + results.Message);
            throw new Exception(": query for Tasks failed: " + results.Message);
        }
        else
        {
            foreach(var res in results.Results)
            {
                emailaddress+= res.artifact.fields[0].value.tostring();
            }
        }
        return 
    }


What I have tried:

Tried returning Ture, false and it is not working and giving error stating cannot convert the List<string>.
Posted
Updated 6-Sep-16 23:18pm
v3
Comments
xszaboj 7-Sep-16 5:18am    
Could you please format your code correctly? But it looks like you need to return List<int> right? That means something like return new List<int>(){1,2,3,4,5,6};

You have to return a List<int>. If that isn't the data you need to return then change the return type so it matches the data you do want to return.
 
Share this answer
 
Comments
Member 8010354 7-Sep-16 5:17am    
That means i have to write
}
return List<int>; ?
Member 8010354 7-Sep-16 5:18am    
When i used
return List<string>;
i am getting an error stating List<string> is a type but used as a variable.
Richard MacCutchan 7-Sep-16 5:30am    
You really need to study C# in more detail.
Member 8010354 7-Sep-16 6:06am    
I will but at this moment, requesting you to help me at this point.
Richard MacCutchan 7-Sep-16 6:14am    
Sorry, but we are not here to do your work for you. If you cannot be bothered to make the effort then do not be surprised when we cannot either. Go to List(T) Class (System.Collections.Generic)[^] and start learning. Either that or go and explain to your manager why you are not interested in being a developer.
Your method definition is invalid, you have:
C#
List<string> int getupdatedetails(int id)
</string>

you can only return one type. So what do you need to return, an int or a List<string></string>? And your return statement is incomplete either way, since it has no return value.
 
Share this answer
 
Comments
Member 8010354 7-Sep-16 5:19am    
I want to return the LIST. If that is the case, how i have to formate the code and what i have to write near return?
Richard MacCutchan 7-Sep-16 5:27am    
Then you need to create the List<string> inside the method, and fill it with values. You then return it at the end, something like:

List<string> getupdatedetails(int id)
{
List<string> myList = new List<string>();

// add strings to your list in the code

return myList;
}
Member 8010354 7-Sep-16 5:36am    
Okay. Understood but as i mentioned my code above, now how to add strings to my list?
Like i used foreach loop to get all the values in it. how to link that with myList?
Richard MacCutchan 7-Sep-16 5:42am    
Look at the documentation for the List<T> class to find the methods available to do what you want.
Member 8010354 7-Sep-16 5:45am    
Actually what i am requesting is, i got the list of values from the code i have mentioned above (Except List<string> getupdatedetails(int artifactID)). But my manager asked me to ad this and return the values. So how to modify the above code to the way you have shown me?

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