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
-
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) { } }
}
-
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) { } }
}
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
-
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) { } }
}
It is the constructor code for a
CartItem
object, although theif
clause would seem redundant, as those two items would (presumably) always need to be set in the constructor. I'm not quite sure why aCartItem
would hold aList
ofCart
objects, but no doubt there is a good reason.Veni, vidi, abiit domum