none
Returning multiple strings from a method RRS feed

  • Question

  • I have a method which return multiple strings.

    The return strings count can be variable.

    For example, this method can return 2 strings like following.

    "AAAAA", "BBBBB"

    In some case, return 3 strings.

    "CCC", "DDDDD", "AA"

    And in some case return ""

    What is proper way to return this kind multiple count of strings?

    Friday, February 2, 2018 12:39 AM

Answers

  • You can return it as a Collection.

    You create List of type Strings and then add to the List and the method will look like as follows,

    Private List<String> GetNames (){
    
    
    }



    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (kokkisajee) or Facebook (sajeetharan) profile for Sajeetharan at Stack Overflow, Q&A for professional and enthusiast programmers

    • Marked as answer by Jeff0803 Friday, February 2, 2018 1:10 AM
    Friday, February 2, 2018 12:45 AM

All replies

  • You can return it as a Collection.

    You create List of type Strings and then add to the List and the method will look like as follows,

    Private List<String> GetNames (){
    
    
    }



    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (kokkisajee) or Facebook (sajeetharan) profile for Sajeetharan at Stack Overflow, Q&A for professional and enthusiast programmers

    • Marked as answer by Jeff0803 Friday, February 2, 2018 1:10 AM
    Friday, February 2, 2018 12:45 AM
  • What is proper way to return this kind multiple count of stringscomma delimited string or empty string
    Friday, February 2, 2018 12:46 AM
  • Is this correct?

    Private List<String> GetNames (){
        List<String> ls = new List<String>();
        //Do Something to fill ls
        
        return ls;
    }

    Friday, April 27, 2018 10:50 PM