static void Main(string[] args) { ElderSon Eson = new ElderSon(); Dad dad = new Dad(Eson); Console.WriteLine(dad.NotifySon("Get me the knife")); YoungerSon Yson = new YoungerSon(); Dad dad2 = new Dad(Yson); Console.WriteLine(dad2.NotifySon("Get me the fork").ToString()); Mom mom = new Mom(); Console.WriteLine(mom.NotifySon(Yson, "Help Me")); Console.WriteLine(mom.NotifySon(Eson, "Help Me")); StepFather StFather = new StepFather(); StFather.FirstSon = Yson; StFather.SecondSon = Eson; Console.WriteLine(StFather.NotifySon("Get the hell out of the house")); StepMother StMother = new StepMother(); StMother.FirstSon = Yson; Console.WriteLine(StMother.NotifySon("First son get out, second son may stay")); Console.ReadKey(); }
public IEnumerable<string> Run() { List<string> errorMessages = new List<string>(); Database.SetInitializer(new DropCreateDatabaseAlways<FamilyMembersWithAttributes>()); var context = new FamilyMembersWithAttributes(); var chris = new Dad() { FirstName = "Chris this is a really long name........", Address = new Address() }; try { context.Dads.Add(chris); errorMessages.AddRange(ValidationHelper.ExtractValidationMessages(context)); context.SaveChanges(); } catch(DbEntityValidationException ex) { errorMessages.Add("Exception thrown when trying to save dad " + ex.ToString()); } return errorMessages; }
public override string ToString() { string res = $"Name:{Name} BirthDate :{birthDate.ToString()}"; if (Mom != null && Dad != null) { res += $"\n{Mom.ToString()}\n{Dad.ToString()}"; } return(res); }
static void Main(string[] args) { var dad01 = new Dad(24, "Me name is dad"); dad01.AgeChange(); var child01 = new Child(2, "name"); child01.AgeChange(); Console.WriteLine($"the dads age is{dad01.Age} and the child is {child01.Age}"); }
// static void Main(string[] args) // { // Console.WriteLine("Hello World!"); // // int xx = 2; // Console.WriteLine(DayPeach(2)+""); // Console.WriteLine(DayPeach(1) + ""); // Console.ReadKey(); // } //static int DayPeach(int whichday) // { // if (whichday == 10) // return 1; // else // if (whichday >= 1) // return 2 * DayPeach(whichday +1) + 2; // else // throw new Exception("天数不正确"); // } #endregion #region 生成连续和任意重复的字符串实例 //static void Main(string[] args) //{ // Program p = new Program();//创建Program对象 // p.CreateSString();//调用自定义方法 // p.CreateTString();//调用自定义方法 // Console.Read(); //} //private void CreateSString() //{ // //生成包含6个连续字符的字符串 // var dd = Enumerable.Range(9, 6).ToArray(); // string str = new string(Enumerable.Range(9, 6).Select(i => (char)(i + 65)).ToArray()); // Console.WriteLine("包含6个连续字符的字符串:" + str); //} //private void CreateTString() //{ // //生成包含3个重复字符串的字符串 // string str = string.Join(string.Empty, Enumerable.Repeat("MR", 3).ToArray()); // Console.WriteLine("包含3个重复字符串的字符串:" + str); //} #endregion #region 获取文件扩展名 //static void Main(string[] args) //{ // string fullPath = @"\WebSite1\Default.aspx"; // string filename = Path.GetFileName(fullPath);//文件名 “Default.aspx” // string extension = Path.GetExtension(fullPath);//扩展名 “.aspx” // Console.ReadKey(); //} #endregion static void Main(string[] args) { Mom mom = new Mom(); Dad dad = new Dad(); Child child = new Child(); mom.Eat += dad.Eat; mom.Eat += child.Eat; mom.Cook(); Console.WriteLine("Press any key to continue........"); Console.ReadKey(true); }
public IEnumerable<string> Run() { List<string> errorMessages = new List<string>(); Database.SetInitializer(new DropCreateDatabaseAlways<FamilyMembersWithAttributes>()); var context = new FamilyMembersWithAttributes(); var chris = new Dad() { FirstName = "Chris", Address = new Address() { City = "Ethan", State = "SD", Zip = "9999999999" } }; var otherDad = new Dad() { FirstName = "Dad with short zip code", Address = new Address() { Zip = "1" } }; try { context.Dads.Add(chris); context.Dads.Add(otherDad); errorMessages.AddRange(ValidationHelper.ExtractValidationMessages(context)); context.SaveChanges(); } catch(DbEntityValidationException ex) { errorMessages.Add("Exception thrown when trying to save dad " + ex.ToString()); } return errorMessages; }
/// <summary> /// despues de annadir llamar a este metodo para reordenar el tree y realizar todas las rotaciones /// </summary> private void ReOrder() { int oldFb = _fb; UpdateFb(); int newFb = _fb; if (oldFb == 0 && (newFb == 1 || newFb == -1) && Dad != null) { Dad.ReOrder(); } else if ((oldFb == 1 || oldFb == -1) && newFb == 0) { return; } else if ((oldFb == 1 || oldFb == -1) && (newFb < -1 || newFb > 1)) { Rotar(this); } }
//test contains correct relation between dad and child set up in db public void SqlServerIntegrationTest() { using (var context = new InMemoryDB()) { var service = new Service(context); var dad = new Dad() { Name = "Tata" }; var person = new Child() { Name = "Pawel", Dad = dad }; context.Add(person); context.SaveChanges(); } using (var context = new InMemoryDB()) { Assert.AreEqual("Pawel", context.Person.Last().Name); } }
protected override void OnModelCreating(ModelBuilder modelBuilder) { // Dads Seeeding var dad1 = new Dad() { Id = 1, Name = "Juan Robles" }; var dad2 = new Dad() { Id = 2, Name = "Rodrigo Lopez" }; modelBuilder.Entity <Dad>().HasData(new Dad[] { dad1, dad2 }); // Moms Sedding Mom mom1 = new Mom() { Id = 1, Name = "Maria Stink" }; Mom mom2 = new Mom() { Id = 2, Name = "Romina Tumbado" }; modelBuilder.Entity <Mom>().HasData(new Mom[] { mom1, mom2 }); // Student Sedding Student student1 = new Student() { Id = 1, Name = "Mario Robles Stink", DadId = 1, MomId = 1 }; Student student2 = new Student() { Id = 2, Name = "Erick Lopez Tumbado", DadId = 2, MomId = 2 }; Student student3 = new Student() { Id = 3, Name = "Martin Lopez Tumbado", DadId = 2, MomId = 2 }; modelBuilder.Entity <Student>().HasData(new Student[] { student1, student2, student3 }); // School Sedding School school1 = new School() { Id = 1, Name = "Instituto Kipling", StudentId = 1 }; School school2 = new School() { Id = 2, Name = "Instituto Benavente", StudentId = 2 }; School school3 = new School() { Id = 3, Name = "Instituto Capistrano", StudentId = 2 }; School school4 = new School() { Id = 4, Name = "Instituto Capistrano", StudentId = 3 }; modelBuilder.Entity <School>().HasData(new School[] { school1, school2, school3, school4 }); }
private void Dad_pressed(object sender, TappedRoutedEventArgs e) { Dad.Play(); }
public static void Main(string[] args) { Console.WriteLine("123"); #region 正则 string line = @"\login\asdads"; Regex reg = new Regex(@"\\(.*?)\\"); Match match = reg.Match(line); string value = match.Groups[1].Value; Console.WriteLine("value的值为:{0}", value); #endregion #region Task回调 TaskFactory taskFactory = new TaskFactory(); List <Task> tastServiceList = new List <Task> (); for (int i = 0; i < 3; i++) { tastServiceList.Add(Task.Run(() => { Console.WriteLine("123"); Thread.Sleep(3000); }).ContinueWith(t => { Console.WriteLine("456"); })); } taskFactory.ContinueWhenAll(tastServiceList.ToArray(), t => { Console.WriteLine("全部完成"); }); #endregion #region 转换 // Dad dad=new Dad(); // Son son=dad;//需要强制转换 Son son = new Son(); Dad dad = son; List <int> li = new List <int> (); IEnumerable <int> le1 = li; IEnumerable <int> le2 = new List <int> (); //li=le2;//不行 li = le2.ToList(); //结论:子类可以赋值父类,反之则不行需要强制转换 #endregion #region 迭代器 Iterator iterator = new Iterator(); // iterator.OddSequence (100, 1000).ToList();//在ToList的时候才调用了OddSequence方法。 //List<int> li= iterator.OddSequence (100, 1000).ToList(); // foreach (var item in li) // { // Console.WriteLine(item); // } #endregion #region 本地方法 Foo foo = new Foo(); var flist = foo.Fibonacci(10).ToList(); //foo.OddSequence (100, 1000);不用ToList()就报错了,这就是本地方法迭代器和普通方法迭代器的在异常上的区别 List <int> list1 = foo.Bar <int> (new int[5] { 0, 1, 2, 3, 4 }).ToList(); //本地方法 // int Sim () { // Console.WriteLine ("打印"); // return 1 + 1; // } //如果你的本地方法只一句代码,可以简化语法。 int Sim() => 1 + 1; Func <int> ff = Sim; int cc = ff(); #endregion #region 时间戳 DateTimeUtil util = new DateTimeUtil(); long l1 = util.ConvertToTimeStmap(Convert.ToDateTime("2020-09-29 13:21:25")); var dt1 = util.ConvertToDateTime(l1); var dt2 = util.TimeStampToDateTime(l1); DateTime timeStamp = new DateTime(1970, 1, 1); long l2 = timeStamp.Ticks; #endregion #region 委托 TestDelegate testDelegate = new TestDelegate(); testDelegate.Use((x1, x2) => { return(x1 - x2); }); testDelegate.Use((x1, x2) => { x1 = 3; x2 = 1; return(x1 - x2); }); testDelegate.Use1((x, y) => { Console.WriteLine("回调"); return(x(3) + y); }); testDelegate.Use2((x) => { return(gbF => { return 1; }); }); int u = testDelegate.Call(9, 4); Console.WriteLine(u); Func <string, string> translation = x => { return(x.ToUpper()); }; GBDataBase gBDataBase = new GBDataBase(); gBDataBase.Excute(1); //执行读操作 gBDataBase.DelegateModeExcute(db => db.ExecuteRead()); //执行读操作 MessageConfigure message = new MessageConfigure(); message.Send(configure => configure.UseEmail()); #endregion #region 引用类型 Person p3 = new Person() { Age = 1 }; Person p4 = p3; //p3,p4存储同一个内存地址 Person p5 = new Person() { Age = 1 }; #endregion #region 属性和索引器 PropertyAndIndex grammar = new PropertyAndIndex(); Console.WriteLine(grammar[1]); #endregion #region 最简单的循环 int[] aa = new int[6] { 1, 2, 3, 4, 5, 6 }; Console.WriteLine(aa.Length); for (int i = 0; i <= aa.Length - 1; i++) { Console.WriteLine(aa[i]); } for (int i = 0; i < aa.Length; i++) { Console.WriteLine(aa[i]); } #endregion #region 动态数组(扩容数组) //缺点,添加元素为object类型,所以存数据和取数据就涉及到了装箱和拆箱的操作,性能低 ArrayList list = new ArrayList(); //List<T> 所以产生了泛型集合 #endregion #region 链表 LinkedList <Person> a = new LinkedList <Person> (); Person p = new Person() { Age = 1, Name = "Gerald" }; a.AddFirst(p); #endregion #region $语法 Console.WriteLine(string.Format("{0}和{1}", "祖国", "人民")); string name1 = "祖国"; string name2 = "人民"; Console.WriteLine($"{name1}和{name2}"); #endregion Log.Logger = new LoggerConfiguration() .MinimumLevel.Debug() .MinimumLevel.Override("Microsoft", LogEventLevel.Information) .Enrich.FromLogContext() .WriteTo.Console() .WriteTo.File(Path.Combine("logs", "api.txt"), rollingInterval: RollingInterval.Day) .CreateLogger(); CreateHostBuilder(args).Build().Run(); }