e.g. 5.12 Implement and Interface in ShoppingCart
e.g. 5.13 An Extension Method That works on an Interface
This commit is contained in:
parent
aa49052a81
commit
f98ec2cbc7
@ -30,10 +30,10 @@ namespace automatically_implemented_properties
|
||||
|
||||
public static class MyExtensionMethod
|
||||
{
|
||||
public static decimal TotalPrices(this ShoppingCart cartParam)
|
||||
public static decimal TotalPrices(this IEnumerable<Product> productEnum)
|
||||
{
|
||||
decimal total = 0;
|
||||
foreach (Product prod in cartParam.Products)
|
||||
foreach (Product prod in productEnum)
|
||||
{
|
||||
total += prod.Price;
|
||||
}
|
||||
|
@ -1,9 +1,20 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace automatically_implemented_properties
|
||||
{
|
||||
public class ShoppingCart
|
||||
public class ShoppingCart : IEnumerable<Product>
|
||||
{
|
||||
public List<Product> Products { get; set; }
|
||||
|
||||
public IEnumerator<Product> GetEnumerator()
|
||||
{
|
||||
return Products.GetEnumerator();
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user