Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8489177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:45:19+00:00 2026-06-10T21:45:19+00:00

class A { public static List<String> a = new List<string>(); public static List<String> test()

  • 0
class A
{
    public static List<String> a = new List<string>();

    public static List<String> test()
    {
        A.a.Add("20");
        A.a.Add("30");
        A.a.Add("40");
        return a.Sort();

    }
}

Throws up a compile error :

Cannot implicitly convert void to System.Collections.Generic.List.

But, If I write a method to get the List<String> value (since it is the static member variable) everything should work fine. But, I am unaware why despite my method returning a List<String> value, why does the compiler throw this error ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T21:45:20+00:00Added an answer on June 10, 2026 at 9:45 pm

    But, I am unaware why despite of my method returning a List value, why does the compiler throw this error ?

    The List<T>.Sort() method doesn’t return a List<T>. It’s a void method – it sorts the list in place. You need:

    a.Sort();
    return a;
    

    Basically a method with a void return type can only be used as a standalone statement. You can’t use it as an expression to return, or as a method argument etc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public class StringPermutation { public static List<String> getPermutation(String input) { List<String> collection = null;
I had a class: public class Constant { public static string ConnString = ConfigurationManager.ConnectionStrings[ConnString].ConnectionString;
i have a class: public class Vars { public static final String NAME =
I have the following in a C# class: public static readonly SortedDictionary<string, string> Fields
I've got the following class: public static class Pages { public static string LoggedOut
I have a class public class A<T> { public static string B(T obj) {
I have a class with a private static List<String> collection. Now I want to
I've got a static class, called Test, and a private List collection. Now I
I created the following Test class: public class GenericTest { public static class A
From Parameter to Property? public class ConcatenateListTMember { public static void Test() { var

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.