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 8888907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:08:01+00:00 2026-06-14T22:08:01+00:00

I have the following code: public IList<Content.Grid> GetContentGrid(string pk) { // How can I

  • 0

I have the following code:

   public IList<Content.Grid> GetContentGrid(string pk)
    {
        // How can I define result to hold the return 
        // data? I tried the following but it does not
        // work:
        var result = new IList<Content.Grid>();

        var data = _contentRepository.GetPk(pk)
             .Select((t, index) => new Content.Grid()
             {
                 PartitionKey = t.PartitionKey
                 ....
             });

        switch (pk.Substring(2, 2))
        {
            case "00":
                return data
                    .OrderBy(item => item.Order)
                    .ToList();
                break;
            default:
                return data
                    .OrderBy(item => item.Order)
                    .ToList();
                break;

        }
    }

The VS2012 is telling me that the break is not needed so what I would like to do is to remove the returns from inside the switch, store the results in a variable and then after the switch is completed have:

return result;

Can someone tell me how I can declare the variable called result. I tried the following but this gives a syntax error:

var result = new IList<Content.Grid>();
  • 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-14T22:08:02+00:00Added an answer on June 14, 2026 at 10:08 pm

    You already return the result in your switch:

    return data
        .OrderBy(item => item.Order)
        .ToList();
    

    There’s no need to declare a variable before/return it after the switch, because you jump out of the switch with the return-statement. (That’s why you don’t need the break)

    However, you could use the following:

    IList<Content.Grid> result;
    

    …

    case "00":
                result = data
                    .OrderBy(item => item.Order)
                    .ToList();
                break;
            default:
                result = data
                    .OrderBy(item => item.Order)
                    .ToList();
                break;
    

    …

    return result;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: public IList<Reference.Grid> GetGrid(string pk) { return ( from d
I have the following code: public IEnumerable<Content.Grid> DetailsBase(string pk) { var data = contentRepository.GetPk(pk);
I have following code public class TEST { public static void main(String arg[]){ try
i have the following code: public static void Serialize() { List<string> dirs = FileHelper.GetFilesRecursive(fileDirectoryPath);
I have the following code: public class AppDomainArgs : MarshalByRefObject { public string myString;
I have the following code: public static IList<SortOption> SortValues() { var sortValues = (from
I have the following example-class: public class MyClass<T> { public IList<T> GetAll() { return
I have the following code: public IList<ProductionRuns> List() { var Shows3Months = (from s
I have the following code: public IList<T_CLIENT> Get_All_Obj() { try { IList<T_CLIENT> LesListe; using
I have the following code for Shuffle so far, public static IList<T> Shuffle<T>(this IList<T>

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.