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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:05:06+00:00 2026-05-26T18:05:06+00:00

I like using c# Auto-Property in code as I found it much more nicer.

  • 0

I like using c# Auto-Property in code as I found it much more nicer. Recently got an idea how I would manage to use Auto-Property, but store the value in Session. Simply for few reason:
– avoid typos in Session item name
– avoid extra code
– possibly for extending to other stores like ViewState, etc.

So far I am thinking the Attribute would be the best option. Just curious if someone tried this before I dig in and start implementing it.

E.g.

[Session] 
public int Id{get;set;}

instead of

public int Id{ get{return Session["Id"];} set{Session["Id"] = value;}}
  • 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-26T18:05:07+00:00Added an answer on May 26, 2026 at 6:05 pm

    No, you can’t do this.

    Automatically implemented properties only work when the desired implementation is a “trivial” property backed by a field. That’s all that’s supported by the compiler. Just about the only way you can “tweak” an automatically implemented property is to set the accessibility of the getter and the setter differently.

    Now of course you could write code to automatically load the value from the session on creation and save it to the session on a particular method call – but that’s not really the same thing.

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

Sidebar

Related Questions

How can I set a string to when using an auto-implemented property like: public
I am using jcarousel to auto scroll some images. I would like to know
I would like to have thread-safe read and write access to an auto-implemented property.
Is there a way to create an auto property via code snippet using ReSharper?
When using auto implemnted properies like public string MyProperty { get; set; } This
When using auto-registration with castle windsor I see people doing things like _container.Register( AllTypes.Pick().FromAssembly(Assembly.GetExecutingAssembly())
I'm using RIM JDE 4.2.1 I'd like my text fields to auto-capitalize the first
Is there a way to turn off auto-complete on an input-field using jQuery? Like
I have a challenging problem where I would like to use reflection on my
I would prefer using constructor injection over JavaBean property injection if I could utilize

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.