Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Product, Category, Composition and Inheritance
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; // aljodav // http://rextester.com/users/376 namespace ForInstance { public interface ICategory{string Name{get;}string Account{get;}} public abstract class Category:ICategory{public string Name{get;protected set;}public string Account{get;protected set;}} public class Hardware:Category{ public Hardware(){Name="Hardware";Account="07-HD-603N";} } // class AnotherCategory:Category{...} public interface IProduct{string Name{get;}int Id{get;}ICategory Category{get;}} public class Product:IProduct,IComparable<Product>{ public int CompareTo(Product p){return this.Name.CompareTo(p.Name);} public string Name{get;set;} public int Id{get;set;} public ICategory Category{get;set;} } } namespace Rextester { using Category=ForInstance.Category; using Hardware=ForInstance.Hardware; using Product=ForInstance.Product; public class Program { public static void Main(string[] args) { // the unique Category object; this object has NO item to be defined in the public Main method. Category hardware= new Hardware(); Product mobo= new Product{Name="Mother Board",Id=101,Category=hardware}; Product fan= new Product{Name="Fan",Id=3,Category=hardware}; Product[] ps={ mobo, new Product{Name="Digital to Analog Converter",Id=531,Category=hardware}, new Product{Name="CPU",Id=332211,Category=hardware}, new Product{Name="Memory",Id=55,Category=hardware}, fan, }; Array.Sort(ps); Array.ForEach(ps,p=>Console.WriteLine("• {0,-28}• {1,-10}• {2,-15}• {3}",p.Name,p.Id,p.Category.Name,p.Category.Account)); } } }
run
|
edit
|
history
|
help
0
Get year quarter from date
My Wall
ejemplo c# 2
vcdgdfgdfdfd
Working nullable DateTime C#
text
TestWall
Action<> usage example
const
Math 9.61