how to return two string values in a C# Class library

how to return two string values in a C# Class library

Page 1 of 1

9 Replies - 14056 Views - Last Post: 23 October 2013 - 12:55 PM Rate Topic: -----

#1 bharathi305   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 18-March 09

how to return two string values in a C# Class library

Post icon  Posted 18 March 2009 - 07:36 AM

how to return two string values in a C# Class library
Is This A Good Question/Topic? 0
  • +

Replies To: how to return two string values in a C# Class library

#2 bharathi305   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 18-March 09

Re: how to return two string values in a C# Class library

Posted 18 March 2009 - 07:38 AM

how to return two string values in a C# Class library
Was This Post Helpful? 0
  • +
  • -

#3 Ryan Marfone   User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 87
  • Joined: 23-February 09

Re: how to return two string values in a C# Class library

Posted 18 March 2009 - 07:43 AM

Post what you have tried and you'll get a better response.
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14101
  • View blog
  • Posts: 56,521
  • Joined: 12-June 08

Re: how to return two string values in a C# Class library

Posted 18 March 2009 - 08:00 AM

with a routine's parameters. you can even put 'ref' in front of the parameter to make sure everyone notices it's by reference.. though I don't think that is necessary since c# should pass everything by ref.
Was This Post Helpful? 0
  • +
  • -

#5 ragingben   User is offline

  • D.I.C Addict
  • member icon

Reputation: 177
  • View blog
  • Posts: 646
  • Joined: 07-October 08

Re: how to return two string values in a C# Class library

Posted 18 March 2009 - 08:15 AM

I think that what you are looking for is to hve a method for your class that returns two strings? If this is so, it is not possible (as far as I know) in the way you are asking for. You could do either of the following

1 - Return an array of some description containing both strings, or...
2 - Return an custom class containing both your string fields. This I would recommend - if your common object you want to return has 2 fields (strings in this case) shouldn't you have a class for it?

This post has been edited by ragingben: 18 March 2009 - 08:16 AM

Was This Post Helpful? 0
  • +
  • -

#6 PsychoCoder   User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1659
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: how to return two string values in a C# Class library

Posted 18 March 2009 - 08:57 AM

Topics merged, please don't create duplicate topics :)
Was This Post Helpful? 0
  • +
  • -

#7 StCroixSkipper   User is offline

  • D.I.C Head
  • member icon

Reputation: 10
  • View blog
  • Posts: 121
  • Joined: 23-December 08

Re: how to return two string values in a C# Class library

Posted 18 March 2009 - 09:16 AM

List<string> Return2Strings()
{
	string one = "string one";
	string two = "string two";
	List<string> stringList = new List<string>();
	stringList.Add(one);
	stringList.Add(two);
	return stringList;


Was This Post Helpful? 0
  • +
  • -

#8 Shavais   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 22-October 13

Re: how to return two string values in a C# Class library

Posted 23 October 2013 - 12:41 PM

View Postbharathi305, on 18 March 2009 - 07:36 AM, said:

how to return two string values in a C# Class library


One way could be to give your class library a function that returns a list of strings, containing the two strings you're after, maybe like this:

    using System.Collections.Generic;

    public List<string> GetName()
    {
        return new List<string> {
            FirstName,  // assuming these class members exist, are strings, and have been populated
            LastName
        };
    }


Was This Post Helpful? 0
  • +
  • -

#9 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14101
  • View blog
  • Posts: 56,521
  • Joined: 12-June 08

Re: how to return two string values in a C# Class library

Posted 23 October 2013 - 12:47 PM

Please watch out with posting on topics that are four years old. Necro'ing isn't always necessary.
Was This Post Helpful? 0
  • +
  • -

#10 Shavais   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 22-October 13

Re: how to return two string values in a C# Class library

Posted 23 October 2013 - 12:55 PM

View Postmodi123_1, on 23 October 2013 - 12:47 PM, said:

Please watch out with posting on topics that are four years old. Necro'ing isn't always necessary.


D'oh! Thanks. How did I end up looking at this question? =P
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1