Jump to content

C sharp, return list

Go to solution Solved by dragosudeki,

Your method has "public static List<string>" but you're returning "List<int>"

I want to use my method witch creates and returns list as a element. I can't make it happen for some reason. Any ideas? 
 

 

 static void Main()
        {

List<int> magic = SentenceCalculationCycle(sentenceNumber, sentenceMessage);

}

 public static List<string> SentenceCalculationCycle(int sentenceNumber, string sentenceMessage)
        {
            var objektas = new Program();
            List<int> sentencesCountList = new List<int>();
            for (int i = 0; i < sentenceNumber; i++)
            {
                string sentence = objektas.StringCheck("sentencePattern", sentenceMessage);
                int charactersCount = objektas.CharCounting(sentence);
                sentencesCountList.Add(charactersCount);
 
            }
           
          return sentencesCountList ;


 

Laptop: Acer V3-772G  CPU: i5 4200M GPU: GT 750M SSD: Crucial MX100 256GB
DesktopCPU: R7 1700x GPU: RTX 2080 SSDSamsung 860 Evo 1TB 

Link to comment
https://linustechtips.com/topic/257912-c-sharp-return-list/
Share on other sites

Link to post
Share on other sites

Your method has "public static List<string>" but you're returning "List<int>"

Thanks. I hope with experience I will become less and less blind :)

Laptop: Acer V3-772G  CPU: i5 4200M GPU: GT 750M SSD: Crucial MX100 256GB
DesktopCPU: R7 1700x GPU: RTX 2080 SSDSamsung 860 Evo 1TB 

Link to comment
https://linustechtips.com/topic/257912-c-sharp-return-list/#findComment-3525395
Share on other sites

Link to post
Share on other sites

Thanks. I hope with experience I will become less and less blind :)

It gets worse in bigger programs. What environment are you using to program? You would normally see a message that you're assigning a List<int> variable to a method that returns List<string>.

Link to comment
https://linustechtips.com/topic/257912-c-sharp-return-list/#findComment-3525446
Share on other sites

Link to post
Share on other sites

It gets worse in bigger programs. What environment are you using to program? You would normally see a message that you're assigning a List<int> variable to a method that returns List<string>.

VS 2013. I'f I'm not mistaken i saw that message. I simply didin't knew what it meas... Started programing recently and English isn't my native language.

Laptop: Acer V3-772G  CPU: i5 4200M GPU: GT 750M SSD: Crucial MX100 256GB
DesktopCPU: R7 1700x GPU: RTX 2080 SSDSamsung 860 Evo 1TB 

Link to comment
https://linustechtips.com/topic/257912-c-sharp-return-list/#findComment-3525479
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×