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

  • Home
  • SEARCH
  • 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 7024565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:51:25+00:00 2026-05-27T23:51:25+00:00

public T Prop = new Ctor(Method); private K Method(U controller, V request); I get

  • 0
public T Prop = new Ctor(Method);

private K Method(U controller, V request);

I get that it can’t access Method here, because Method is required to be static. Why is this? Prop is not static.

Update: Here’s the actual signature:

public DataSource(Func<ControllerBase, AjaxDataTable.Request, Result> dataSelector)

And this is how the method used to be:

public AjaxDataTable<SourcesViewModel.Source.Channel>.DataSource AjaxData =
    new AjaxDataTable<SourcesViewModel.Source.Channel>.DataSource(OnSelectData);

This wasn’t an issue because I didn’t need to reference this, so when I added this and it didn’t compile anymore, (the field wasn’t mine to begin with, someone else had done it like that, so don’t hate me for that). I changed it to the following:

private AjaxDataTable<SourcesViewModel.Source.Channel>.DataSource ajaxData;
public AjaxDataTable<SourcesViewModel.Source.Channel>.DataSource AjaxData
{
    get
    {
        if (ajaxData == null)
        {
            ajaxData =
                new AjaxDataTable<SourcesViewModel.Source.Channel>
                    .DataSource(OnDataSelector);
        }
        return ajaxData;
    }
}

But then the ajaxData private field would always be null, which makes the data table be instanced again every time (this is appended into a concurrent dictionary, which causes an Exception on a duplicate key). I want to know how assigning to a field that doesn’t reference this works. Does that create something that is reused across all instances of an object?

  • 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-27T23:51:26+00:00Added an answer on May 27, 2026 at 11:51 pm

    This is due to section 10.5.5.2 of the C# 4 spec, which includes:

    A variable initializer for an instance field cannot reference the instance being created. Thus it is a compile-time error to reference this in a variable initializer […]

    You’re effectively referencing this, as your code is equivalent to:

    public T Prop = new Ctor(this.Method);
    

    Now you can argue that this restriction is draconian, but that’s a different discussion. Note that you could put it into a constructor body:

    public T Prop;
    
    public Foo()
    {
        Prop = new Ctor(Method);
    }
    

    (I’m assuming you wouldn’t really have a public field, and that you’d have sensible names, etc 🙂

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

Sidebar

Related Questions

Ok, so C# has properties public int Prop {get;set;} I can put the getter
public Properties prop = new Properties(); I get an illegal start of expression error
This is the scenario: class BaseClass { public virtual string Prop {get; set;} }
public class Class1 { public Class1() { prop = new Class2(); } public Class2
I have a method: public static void GetObjects() { using(MyContext context = new MyContext())
private HibernateTemplate hibernateTemplate; public void setSessionFactory(SessionFactory sessionFactory) { this.hibernateTemplate = new HibernateTemplate(sessionFactory); } What
public static void main(String[] args) { List<? extends Object> mylist = new ArrayList<Object>(); mylist.add(Java);
public static IList<T> LoadObjectListAll<T>() { ISession session = CheckForExistingSession(); var cfg = new NHibernate.Cfg.Configuration().Configure();
public static Logger getLogger() { final Throwable t = new Throwable(); final StackTraceElement methodCaller
public class Address { public string ZipCode {get; set;} } public class Customer {

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.