Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Properties error in C#

Properties error in C#

Scheduled Pinned Locked Moved C#
csharphelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gopinathtamil
    wrote on last edited by
    #1

    i have tried using below coding for shopping cart functionality...but it shows below error... Error: CS0501: 'CartItem.Quantity.get' must declare a body because it is not marked abstract or extern Coding

    using System;

    public class CartItem : IEquatable {
    #region Properties

    public int Quantity
    {
        get;
        set;
    }
    
    private int \_productId;
    
    public int ProductId 
    {
    	get 
        { 
            return \_productId; 
        }
    	set 
        {
    		\_productId = value;
    	}
    }
    
    private Product \_product = null;  
    
    public Product Prod 
    {
    	get 
        {
    		if (\_product == null) 
            {
    			\_product = new Product(ProductId);
    		}
    		return \_product;
    	}
    }
    
    public string Description 
    {
    	get 
        { 
            return Prod.Description; 
        }
    }
    
    public decimal UnitPrice 
    {
    	get 
        { 
            return Prod.Price; 
        }
    }
    public string productname
    {
        get
        {
            return Prod.Productname;  
        }
    }
    
    public decimal TotalPrice 
    {
    	get 
        { 
            return UnitPrice \* Quantity; 
        }
    }
    
    #endregion
    
    public CartItem(int productId) 
    {
    	this.ProductId = productId;
    }
    
    public bool Equals(CartItem item) 
    {
    	return item.ProductId == this.ProductId;
    }
    

    }

    L 1 Reply Last reply
    0
    • G gopinathtamil

      i have tried using below coding for shopping cart functionality...but it shows below error... Error: CS0501: 'CartItem.Quantity.get' must declare a body because it is not marked abstract or extern Coding

      using System;

      public class CartItem : IEquatable {
      #region Properties

      public int Quantity
      {
          get;
          set;
      }
      
      private int \_productId;
      
      public int ProductId 
      {
      	get 
          { 
              return \_productId; 
          }
      	set 
          {
      		\_productId = value;
      	}
      }
      
      private Product \_product = null;  
      
      public Product Prod 
      {
      	get 
          {
      		if (\_product == null) 
              {
      			\_product = new Product(ProductId);
      		}
      		return \_product;
      	}
      }
      
      public string Description 
      {
      	get 
          { 
              return Prod.Description; 
          }
      }
      
      public decimal UnitPrice 
      {
      	get 
          { 
              return Prod.Price; 
          }
      }
      public string productname
      {
          get
          {
              return Prod.Productname;  
          }
      }
      
      public decimal TotalPrice 
      {
      	get 
          { 
              return UnitPrice \* Quantity; 
          }
      }
      
      #endregion
      
      public CartItem(int productId) 
      {
      	this.ProductId = productId;
      }
      
      public bool Equals(CartItem item) 
      {
      	return item.ProductId == this.ProductId;
      }
      

      }

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      reread the error message, then compare the code for properties Quantity and ProductId. What you have is called an "auto-implemented property", which is rather new. Either fix the code or switch to the latest .NET version and rebuild. :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      Avoiding unwanted divs (as in "articles needing approval") with the help of this FireFox add-in


      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups