Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2015
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.16 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace WcfFromConsole
  8. {
  9.     public class Products
  10.     {
  11.         private static readonly Products _instance = new Products();
  12.  
  13.         private Products() { }
  14.  
  15.         public static Products Instance { get { return _instance; } }
  16.  
  17.         public List<Product> ProductList { get { return products; } }
  18.  
  19.         private List<Product> products = new List<Product>()
  20.         {
  21.             new Product() {ProductId=1,Name="test1" },
  22.             new Product() {ProductId=2,Name="test2" }
  23.         };
  24.  
  25.         public Product GetProduct(int id)
  26.         {
  27.             for (int i = 0; i < ProductList.Count; i++)
  28.             {
  29.                 if (ProductList[i].ProductId == id)
  30.                 {
  31.                     return ProductList[i];
  32.                 }
  33.             }
  34.             return null;
  35.         }
  36.     }
  37.  
  38.         [DataContract]
  39.         public class Product
  40.         {
  41.             [DataMember]
  42.             public int ProductId { get; set; }
  43.  
  44.             [DataMember]
  45.             public string Name { get; set; }
  46.         }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement