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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:31:51+00:00 2026-06-17T11:31:51+00:00

So, I have an encryption key in my code like: private const string _keyc

  • 0

So, I have an encryption key in my code like:

private const string _keyc = "blahblahblah";

private static string _key
{
     get { return "blahblahblah"; }
}

After compilation, on ILDasm, I do notice that I can just see the value of the constant directly, but not in the second case. However, I can still see the key in ldstr under hidebysig...get_key()

ILSpy however obtained back the source code exactly the way I wrote it.

So here, I’m wondering, does it really make sense to use an auto property here? Are there any other advantages in using auto properties? Specifically in this type of simple case, would it be advisable to use an auto property? Thanks!

  • 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-17T11:31:51+00:00Added an answer on June 17, 2026 at 11:31 am

    You can use automatic properties only when:

    • The property is read-write; that is, it defines both get and set accessors. If you are only defining one accessor, you cannot use automatic properties. (Note that you can define a private set accessor on an automatic property if you want the property to be read-only from code outside of the class, but read-write from inside the class.)
    • You do not need to do any verification in the setter — that is, all values of the property type are valid.
    • You do not need to initialize the backing field directly, but instead will set the property from a constructor (or just leave the default value in the field).
    • You never need to reference the backing field directly, for example as a ref or out parameter. In particular, this will prevent you from using the System.Threading.Interlocked methods on the field.
    • The name of the field is not important. (Serialization is a case where it might be considered important.)

    Based on your example, you are implementing a read-only property (one with no setter). You cannot use automatic properties in this case, unless you use a pattern like this:

    class Example
    {
        public static string SomeProperty { get; private set; }
    
        static Example()
        {
            SomeProperty = "some value";
        }
    }
    

    However, just returning the constant value from a getter is much less complex, and should be preferred:

    class Example
    {
        public static string SomeProperty
        {
            get { return "some value"; }
        }
    }
    

    This code is clear and to the point. Automatic properties are supposed to make your code more readable. In this case they would actually obfuscate intent, so I would not use one here.


    Note that the property in your example code is not an automatic property at all; it’s just a standard property. Automatic properties declare a getter and setter, but do not provide an implementation.

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

Sidebar

Related Questions

I have a private key and exponent, i need to implement RSA encryption of
I have a .NET method for doing DES encryption on a string: public static
I have test input string (key=value&key=value...) and key (like this D2335A9CA4924D9F914D2B47B450D436) I need to
I have this Telerik radgrid | Encryption Key | Password to encode | Edit
I know very little about encryption/hashing. I have to hash an encryption key. The
I have a PHP script that does basic encryption of a string through the
Is there any way to perform private key encryption in C#? I know about
I have this following snippet from c++ code that is used for encryption: EVP_CIPHER_CTX
I have my pre generated AES key what i would like to use in
I have basic code that looks like this: while(inputfileStream.good()) { for(int i = 0;i<levels;i++)

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.