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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:38:57+00:00 2026-05-24T08:38:57+00:00

Is this valid C# code ? public class Product { [CompilerGenerated] private string <Name>k__BackingField;

  • 0

Is this valid C# code ?

  public class Product
  {
        [CompilerGenerated]
        private string <Name>k__BackingField;

    [CompilerGenerated]
    private decimal <Price>k__BackingField;

    public string Name
    {
     get;
     private set;
    }

    public decimal Price
    {
     get;
     private set;
    }

    public Product() 
        {
        }

    public static List<Product> GetSampleProducts()
    {
     List<Product> products = new List<Product>();
     Product num1.Price = new decimal(1233, 0, 0, false, 2).Add(num1);
     Product product1.Price = new decimal(1332, 0, 0, false, 2).Add(product1);
     Product num2.Price = new decimal(2343, 0, 0, false, 2).Add(num2);
     Product product2.Price = new decimal(2355, 0, 0, false, 2).Add(product2);
     return products;
    }

    public override string ToString()
    {
     return string.Format("{0}: {1}", this.Name, this.Price);
    }
   }

The example above is taken from JustDecompile ( a .NET decompiler ) you can see the original version below:

using System;
using System.Collections.Generic;
using System.Text;

namespace ProductV3
{
   public class Product
   {
       public string Name { get; private set; }
       public decimal Price { get; private set; }

       public Product() { }

       public static List<Product> GetSampleProducts()
       {
          return new List<Product>()
          {
              new Product() { Name = "ProductA", Price = 12.33M },
              new Product() { Name = "ProductB", Price = 13.32M },
              new Product() { Name = "ProductC", Price = 23.43M },
              new Product() { Name = "ProductD", Price = 23.55M }
          };
       }

       public override string ToString()
       {
          return string.Format("{0}: {1}", Name, Price);
       }
   }
}

I want to know if the first listing is a decompiling error or if it is valid C# code, generated by the compiler. I am very curios what is with the code in the method GetSampleProducts.

  • 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-24T08:38:58+00:00Added an answer on May 24, 2026 at 8:38 am

    It’s pretty simple to see that it’s not valid C# code by pasting it into a compiler and trying to compile it.

    It seems like the decompiler doesn’t know how to properly handle auto-properties and the object literal syntax (not sure if that’s the proper term)

    One thing with <Price>k__BackingField that is actually the name of the backing field generated in IL. < and > aren’t valid parts of an identifier name in C# however they are in IL which is why they receive that name when auto-properties are compiled, so it doesn’t conflict with any variable names you might create yourself. Auto-properties are just compiler magic that actually does create a private field in the background after all.

    With a more complete decompiler you’ll get better results, for example, this is what DotPeek gives when decompiling (even optimized with debugging symbols removed):

      public class Product
      {
        public string Name { get; private set; }
    
        public Decimal Price { get; private set; }
    
        public static List<Product> GetSampleProducts()
        {
          return new List<Product>()
          {
            new Product()
            {
              Name = "ProductA",
              Price = new Decimal(1233, 0, 0, false, (byte) 2)
            },
            new Product()
            {
              Name = "ProductB",
              Price = new Decimal(1332, 0, 0, false, (byte) 2)
            },
            new Product()
            {
              Name = "ProductC",
              Price = new Decimal(2343, 0, 0, false, (byte) 2)
            },
            new Product()
            {
              Name = "ProductD",
              Price = new Decimal(2355, 0, 0, false, (byte) 2)
            }
          };
        }
    
        public override string ToString()
        {
          return string.Format("{0}: {1}", (object) this.Name, (object) this.Price);
        }
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This isn't valid code: public class MyClass { private static boolean yesNo = false;
I tried this but it does not seem to be valid syntax. <xsl:element name=$myElementName></xsl:element>
Like this: public class remoteStatusCounts : RemoteStatus { public int statusCount; public remoteStatusCounts(RemoteStatus r)
If I have the following code: public class Foo { public void Bar() {
Is the following code legal in C++. Accessing a friend class member public method?
I am getting error the modifier public is not valid for this item this
This code verifies whether an ISBN is valid. For nine-digit inputs, I'd like to
//node.h class node { public: void sort(node n); }; I didn't try the code
Is this valid and correct? RewriteRule ^myOldPage.html$ /index.php#info [R] I'm specifically interested about the
I'm getting XML like this: <Items> <Row attr1=val></Row> <Row attr1=val2></Row> </Items> This is valid

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.