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
  1. Home
  2. Web Development
  3. ASP.NET
  4. Can you help me in this token? if(this._Item==null){ this._Item = new List<Cart>(); this._dateCreate = DateTime.Now; } }.I do not understand it and why use

Can you help me in this token? if(this._Item==null){ this._Item = new List<Cart>(); this._dateCreate = DateTime.Now; } }.I do not understand it and why use

Scheduled Pinned Locked Moved ASP.NET
csharplinqhelpquestion
3 Posts 3 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.
  • D Offline
    D Offline
    Danh Le
    wrote on last edited by
    #1

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;

    namespace Shopping
    {
    public class Cart
    {
    private int _IDproduct;
    private string _nameProduct;
    private int _Quantity;
    private string _ImageUrl;
    private double _Price;
    private double _Total;

       public Cart(){}
       public  Cart(int IDProduct, string NameProduct, int Quantity, string ImageURL, double Price){
    
           \_IDproduct = IDProduct;
           \_nameProduct = NameProduct;
           \_Quantity = Quantity;
           \_ImageUrl = ImageURL; ;
           \_Price = Price;
           \_Total = Price\*Quantity;
                }
       public int IDProduct {
           get { return \_IDproduct; }
           set { \_IDproduct = value; }
       }
    
       public string NameProduct
       {
           get { return \_nameProduct; }
           set { \_nameProduct = value; }
       }
    
       public int Quantity
       {
           get { return \_Quantity; }
           set { \_Quantity = value; }
       }
    
       public string ImageURL
       {
           get { return \_ImageUrl; }
           set { \_ImageUrl = value; }
       }
    
       public double Price
       {
           get { return \_Price; }
           set { \_Price = value; }
       }
    
       public double Total
       {
           get { return \_Price\*\_Quantity; }
    
       }
             }
    
        public  class CartItem{
    
            private DateTime \_dateCreate;
            private DateTime \_dateUpdate;
            private List<Cart> \_Item;
            public CartItem() {
    
             if(this.\_Item==null){
    
                     this.\_Item = new List<Cart>();
                     this.\_dateCreate = DateTime.Now;
             }
                        }
    
            public List<Cart> Item {
                get { return \_Item; }
                set { \_Item = value; }
            }
    
            public void Insert(int IDProduct, int Quantity, string ImageURL, string NameProuct, double Price) {
    
    
            }
    
    
        }
    

    }

    J L 2 Replies Last reply
    0
    • D Danh Le

      using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Web;

      namespace Shopping
      {
      public class Cart
      {
      private int _IDproduct;
      private string _nameProduct;
      private int _Quantity;
      private string _ImageUrl;
      private double _Price;
      private double _Total;

         public Cart(){}
         public  Cart(int IDProduct, string NameProduct, int Quantity, string ImageURL, double Price){
      
             \_IDproduct = IDProduct;
             \_nameProduct = NameProduct;
             \_Quantity = Quantity;
             \_ImageUrl = ImageURL; ;
             \_Price = Price;
             \_Total = Price\*Quantity;
                  }
         public int IDProduct {
             get { return \_IDproduct; }
             set { \_IDproduct = value; }
         }
      
         public string NameProduct
         {
             get { return \_nameProduct; }
             set { \_nameProduct = value; }
         }
      
         public int Quantity
         {
             get { return \_Quantity; }
             set { \_Quantity = value; }
         }
      
         public string ImageURL
         {
             get { return \_ImageUrl; }
             set { \_ImageUrl = value; }
         }
      
         public double Price
         {
             get { return \_Price; }
             set { \_Price = value; }
         }
      
         public double Total
         {
             get { return \_Price\*\_Quantity; }
      
         }
               }
      
          public  class CartItem{
      
              private DateTime \_dateCreate;
              private DateTime \_dateUpdate;
              private List<Cart> \_Item;
              public CartItem() {
      
               if(this.\_Item==null){
      
                       this.\_Item = new List<Cart>();
                       this.\_dateCreate = DateTime.Now;
               }
                          }
      
              public List<Cart> Item {
                  get { return \_Item; }
                  set { \_Item = value; }
              }
      
              public void Insert(int IDProduct, int Quantity, string ImageURL, string NameProuct, double Price) {
      
      
              }
      
      
          }
      

      }

      J Offline
      J Offline
      Joshua Omundson
      wrote on last edited by
      #2

      I'm not sure what your question exactly is.

      if(this._Item==null)

      This statement checks to see if the list has anything in it. If it doesn't then it will create a new list so you can store Cart objects in it

      1 Reply Last reply
      0
      • D Danh Le

        using System;
        using System.Collections.Generic;
        using System.Linq;
        using System.Web;

        namespace Shopping
        {
        public class Cart
        {
        private int _IDproduct;
        private string _nameProduct;
        private int _Quantity;
        private string _ImageUrl;
        private double _Price;
        private double _Total;

           public Cart(){}
           public  Cart(int IDProduct, string NameProduct, int Quantity, string ImageURL, double Price){
        
               \_IDproduct = IDProduct;
               \_nameProduct = NameProduct;
               \_Quantity = Quantity;
               \_ImageUrl = ImageURL; ;
               \_Price = Price;
               \_Total = Price\*Quantity;
                    }
           public int IDProduct {
               get { return \_IDproduct; }
               set { \_IDproduct = value; }
           }
        
           public string NameProduct
           {
               get { return \_nameProduct; }
               set { \_nameProduct = value; }
           }
        
           public int Quantity
           {
               get { return \_Quantity; }
               set { \_Quantity = value; }
           }
        
           public string ImageURL
           {
               get { return \_ImageUrl; }
               set { \_ImageUrl = value; }
           }
        
           public double Price
           {
               get { return \_Price; }
               set { \_Price = value; }
           }
        
           public double Total
           {
               get { return \_Price\*\_Quantity; }
        
           }
                 }
        
            public  class CartItem{
        
                private DateTime \_dateCreate;
                private DateTime \_dateUpdate;
                private List<Cart> \_Item;
                public CartItem() {
        
                 if(this.\_Item==null){
        
                         this.\_Item = new List<Cart>();
                         this.\_dateCreate = DateTime.Now;
                 }
                            }
        
                public List<Cart> Item {
                    get { return \_Item; }
                    set { \_Item = value; }
                }
        
                public void Insert(int IDProduct, int Quantity, string ImageURL, string NameProuct, double Price) {
        
        
                }
        
        
            }
        

        }

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        It is the constructor code for a CartItem object, although the if clause would seem redundant, as those two items would (presumably) always need to be set in the constructor. I'm not quite sure why a CartItem would hold a List of Cart objects, but no doubt there is a good reason.

        Veni, vidi, abiit domum

        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