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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:04:23+00:00 2026-05-26T00:04:23+00:00

I have a class divided in two partial files, like this: public partial class

  • 0

I have a class divided in two partial files, like this:

public partial class PersonRepository : BaseRepository<Person>
{
    public static readonly string ColumnID = "ID";
    ...

and

public partial class PersonRepository : BaseRepository<Person>
{
    public List<Person> GetByCompany(int companyID, string sortExpression = ColumnID)
    {
    ...

But the compiler keeps saying that sortExpression “must be a compile-time constant”. To me it seems a perfect compile-time constant, so I don’t understand where the problem is.

  • 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-05-26T00:04:24+00:00Added an answer on May 26, 2026 at 12:04 am

    No, the expression PersonRespository.ColumnID is not classified as a compile-time constant. The expression “ID” is, but that’s not what you’re using as the default parameter.

    In particular, if ColumnID is “just a normal field” then any references to it will be resolved as a field – so if you compile an assembly which refers to the field, then change the value and rebuild the assembly containing PersonRepository, the referring assembly will see that change.

    If you change your declaration to:

     public const string ColumnID = "ID";
    

    then it is a compile-time constant expression. That means in our previous scenario, the value of the constant is baked into any code that refers to it – and changing the value later without recompiling that referring code won’t change the value used by that referring code.

    See section 7.19 of the C# 4 language specification for more details about what counts as a constant expression.

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

Sidebar

Related Questions

I have class that represents users. Users are divided into two groups with different
I have a form that is divided into two classes. Each class represents the
I have a large class, which I have divided into several different class extension
I have class A: public class ClassA<T> Class B derives from A: public class
i have a problem with this class. the goal is to make the main
I have the following string that I would like to Huffman-encode and store efficiently
I have a div that is divided into two parts. left and right. it
I have a college programming project in C++ divided into two parts. I beggining
I have my screen divided into two DIV s. In the left DIV I
I have this frame-based counter I use instead of the timer-class because everything in

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.