static void Main(string[] args) { Person p = new Person(); //We used to have to do lots of nested if statements: if(p.Child == null) Console.WriteLine(0); else Console.WriteLine(p.Child.NumberOfArms); //Now we can do this: Console.WriteLine(p.Child?.NumberOfArms); //We can also use ?? Console.WriteLine(p.Child?.Address?.Address1??"No Address"); //This is one of my favourite features - string interpolation! So much cleaner than using string.Format string name = "Bob"; int age = 25; decimal money = 42.6M; string output = $"{name} is {age} years old and has {money:C} in his pocket."; Console.WriteLine(output); Console.ReadKey(); }
static void Main(string[] args) { Person myp = new Person(); myp.Age = 38; Console.Write(myp.Age); //This constructs the object. //Looks like anon class in Java. Construct cDo = new Construct() { Name = "Jason", JobCode = 8675309 }; Console.WriteLine("Enter one - three"); //Convert a String read from the user input to an INT. int result = int.Parse(Console.ReadLine()); switch (result) { case 1: Console.WriteLine("You entered:{0} ", result); break; case 3: Console.WriteLine("You entered:{0} ", result); break; case 2: Console.WriteLine("You entered:{0} ", result); break; default: break; } }
static void Main(string[] args) { Person person = new Person(); person.Name = "StarLee"; person.Sex = 'M'; person.Age = 28; }
public void printArchive(Person[] pv) { foreach (Person p in pv) { Console.WriteLine(p.ToString()); } }
public void MyMethod(ref Person employee, ref int count) { Console.WriteLine("MyMethod - parameter values: {0}, {1}", employee.Name, count); employee = new Person("Joe Smith"); count = 20; Console.WriteLine("MyMethod - modified parameter values: {0}, {1}", employee.Name, count); }
// sobstitute th first with the last in the index public void removePerson(Person p) { if (this.getPerson().Equals(p)) { this.setPerson(this.getLast()); this.removeLast(); } else if (this.isLast()) { this.removePerson0(p); } }
// build a vector of people public Person[] buildvector(Person[] pv) { x = new Random(); x.Next(8); for (int i = 0; i < pv.Length; i++) { pv[i] = new Person(namefiller(x.Next()), lastnamefiller(x.Next()), redditofiller(x.Next()), jobfiller(x.Next())); } return pv; }
static public void Do() { var peroson = new Person(); Console.WriteLine(peroson.getName()); var taro = new Taro(); Console.WriteLine(taro.getName()); Person someone = new Taro(); Console.WriteLine(someone.getName()); }
public void Age_Validage_calculatesCorrectly() { //Arrange Person p = new Person(); p.DateOfBirth = new DateTime(1992,05,13); //Act int result = p.Age; //Assert Assert.AreEqual(23, result); }
public void ZodiacSign_DisplayCorrectSign() { //Arrange Person p = new Person(); p.DateOfBirth = new DateTime(1992, 05, 13); //Act String ZodiacSign = p.ZodiacSign; //Assert Assert.AreEqual("Taurus", ZodiacSign); }
static void Main(string[] args) { Person anyPerson = new Person(); anyPerson.FirstName = "Priyanka"; anyPerson.LastName = "Beekharry"; anyPerson.DateOfBirth = new DateTime(1992,05,13); Console.WriteLine(anyPerson.FirstName); Console.WriteLine(anyPerson.Age); Console.WriteLine(anyPerson.FullName); Console.WriteLine(anyPerson.ZodiacSign); Console.ReadKey(); }
public void FullName_Valid_DisplayCorrectFullName() { //Arrange Person p = new Person(); p.FirstName = "Bill"; p.LastName = "Clinton"; //Act String result = p.FullName; //Assert Assert.AreEqual("Bill Clinton", result); }
public static void Listing9_12() { Person myperson = new Person("John Doe"); int mycount = 10; Console.WriteLine("MAin Method - variables values before: {0}, {1}", myperson.Name, mycount); MyClass mc = new MyClass(); mc.MyMethod(ref myperson, ref mycount); Console.WriteLine("Main Method - variable values after: {0}, {1}", myperson.Name, mycount); Console.WriteLine("Press enter to finish"); Console.ReadLine(); }
static void Main(string[] args) { // new features in C# 6 // null propagating operator // string interpolation // auto property initialisation // nameof operator Console.WriteLine($"Propertyname: {Person.FirstNamePropertyName}"); var persons = new List<Person>(); var p1 = new Person(); persons.Add(p1); var p2 = new Person { FirstName = $"{p1.FirstName} Sepp" }; persons.Add(p2); Person p3 = null; persons.Add(p3); // runtime exception filter with when foreach (var p in persons) { //var firstname = p?.FirstName; //if (firstname == null) // firstname = "null"; //Console.WriteLine($"{firstname} {p?.LastName}"); try { Console.WriteLine($"{p.FirstName} {p.LastName}"); } catch(NullReferenceException) when (p == null) { Console.WriteLine("person is null"); } } // new dictionary initializer //var dict = new Dictionary<int, Person> //{ // [1] = p1 //}; // expresson bodied members Console.WriteLine($"Fullname: {p1.GetFullName()}"); Console.ReadKey(); }
static void Main(string[] args) { string[] atts = { "Sophie", "Greene", "1/12/1991", "30 Some Street", "", "Leeds", "West Yorkshire", "ZE7 3AE", "UK","Student" }; string[] att = { "Manual", "Zu", "1/12/1937", "30 Other Street", "", "Sheffield", "West Yorkshire", "LE7 9MN", "UK","Teacher" }; Person student = new Person(atts); student.print(); Person teacher = new Person(att); teacher.print(); //ensure console window stays open string[] pAtt = {"Intro to Computer Science","Some Guy","BSc. blah blah" }; UProgram prog = new UProgram(pAtt); prog.print(); Degree deg = new Degree("Bsc. A M", 72); deg.print(); Course cour = new Course("Intro hbla", 3, 9, "Mr blah Person"); cour.print(); Console.Read(); }
static void Main(string[] args) { string sub; Person p1 = new Person(); p1.Message(); Student s1 = new Student(); s1.SetAge(21); s1.Message(); s1.ShowAge(); Teacher t1 = new Teacher(); t1.SetAge(30); t1.Message(); t1.ShowAge(); Console.WriteLine("Enter the subject:"); sub = Console.ReadLine(); t1.SetSub(sub); t1.Explain(); Console.Read(); }
static void Main(string[] args) { Console.WriteLine("Person--Student--ExStudent: "); Console.WriteLine(); Person person1 = new Person("Vasia",26); Person person2 = new Person("Petia", 25); person1.ShowInfo(); person2.ShowInfo(); Person person3 = new Student("Vasia", 26,"BSU"); Person person4 = new Student("Petia", 25, "BrSU"); Console.WriteLine(); person3.ShowInfo(); person4.ShowInfo(); Person person5 = new ExStudent("Vasia", 26, "BSU", "Brest"); Person person6 = new ExStudent("Petia", 25, "BrSU", "Minsk"); Console.WriteLine(); person5.ShowInfo(); person6.ShowInfo(); }
static void Main(string[] args) { //create a person object Person josh = new Person("Josh", 26, 130); //create our cars inventory List<Car> carInventory = new List<Car>(); //create cities List<City> cities = new List<City>(); City city1 = new City("New York City", 100); City city2 = new City("Chicago", 200); cities.Add(city1); cities.Add(city2); //add cars to the inventory Car car1 = new Car("volkswagon", "gti", 2015, 25000); Car car2 = new Car("mazda", "3", 2014, 20000); Car car3 = new Car("subaru", "impreza", 2015, 23000); carInventory.Add(car1); carInventory.Add(car2); carInventory.Add(car3); //invoke methods on the person object josh.personInfo(); josh.workOut(50); //josh.buyCar("Volkswagon", "GTI", carInventory); josh.buyCar("3", "Mazda", carInventory); josh.viewCars(); //josh.driveCar("Mazda", "3", cities, "Chicago"); josh.driveCar("Mazda", "3", cities, "New York City"); Console.ReadLine(); }
// build the job's lists public List<ListNode> joblist(Person[] pv) { bool b; List<ListNode> job = new List<ListNode>(); job.Add(new ListNode(pv[0],pv[0].getJob())); for (int i = 1; i < pv.Length; i++) { b = true; for (int j = 0; j < job.Count && b; j++) { if (pv[i].getJob().Equals(job[j].getParameter())&& b) { job[j].addLast(pv[i]); b = false ; } } if (b) { job.Add(new ListNode(pv[i], pv[i].getJob())); } } return job; }
static void Main(string[] args) { #region Args foreach (string arg in args) { Console.WriteLine(arg); } #endregion Person p = new Person(new RetardedPersonFactory()); Console.WriteLine(p.Arm.fingers); Console.ReadLine(); //cd "Documents and Settings\alan\My Documents\Visual Studio 2010\Projects\Console_practice\Console_practice\bin\Debug" }
static void Main(string[] args) { Pupil aurel = new Pupil("Aurel", 6, 1); Pupil quentin = new Pupil("Quentin", 22, 1); Pupil paul = new Pupil("Paul", 5, 1); Person maxime = new Person("Maxime", 10); Person chris = new Person("Chris", 2); Pupil aurel2 = new Pupil("Aurel", 6, 1); Pupil quentin2 = new Pupil("Quentin", 22, 1); Pupil jean = new Pupil("Jean", 5, 1); List<Person> listPersons = new List<Person>(); List<Pupil> listPupils = new List<Pupil>(); List<Pupil> listPupilsDuplicated = new List<Pupil>(); listPupilsDuplicated.Add(aurel2); listPupilsDuplicated.Add(quentin2); listPupilsDuplicated.Add(jean); //{ // new Pupil("Aurel", 6, 1); // new Pupil("Quentin", 22, 1); // new Pupil("Paul", 5, 1); //} listPupils.Add(aurel); listPupils.Add(quentin); listPupils.Add(paul); listPersons.Add(maxime); listPersons.Add(chris); var listFusion = listPersons.Union(listPupils); IEnumerable<Pupil> listPupilsNoDuplicated = listPupilsDuplicated.Distinct<Pupil>(new PersonComparer()); foreach (var pers in listPupilsNoDuplicated) { System.Console.Write(pers); } Debug. System.Console.Read(); Activity act1 = new Activity("coloriage", true); Activity act2 = new Activity("français", false); Activity act3 = new Activity("sieste", true); //aurel.AddActivity(act1); //aurel.AddActivity(act2); //aurel.AddActivity(act3); aurel.AddActivity("français"); aurel.AddActivity("sieste"); aurel.AddEvaluation("coloriage"); aurel.AddEvaluation(evaluation: 'T', title: "sieste"); // var pupilGrade1Plus6 = from pupil in listPupils // where pupil.Grade == 1 && pupil.Age >= 6 // select pupil; var pupilGrade1Plus6 = listPupils.FindAll(p => p.Grade == 1 && p.Age >= 6); if (pupilGrade1Plus6 != null) { foreach (var pupil in pupilGrade1Plus6) { System.Console.Write(pupil); } } //System.Console.Write(aurel); System.Console.Read(); }
// public void setOther(ListNode l) { other = l; } void setPerson(Person l) { p = l; }
public ListNode(Person p, string s) { this.p = p; this.s = s; }
// add a new son node as last public void addLast(Person p) { if (this.isLast()) { this.getNext().addLast(p); } else this.setNext(new ListNode(p, p.getJob())); }
public Builder(Person person) { this.Person = person; }
public void Build(Person person) { person.BuildHead(); Person.BuildBody(); person.BuildLag(); }
static void Main(string[] args) { List<Student> Cheloveki = new List<Student>(); Education SomeEd1 = (Education)1; Education SomeEd2 = (Education)2; Education SomeEd3 = (Education)3; Person Person1 = new Person("Александр", "Григорьев", new DateTime(1990, 10, 15)); Student studP1 = new Student(Person1, SomeEd1, 32); Cheloveki.Add(studP1); bool work = true; while (work) { //Вывод меню Console.Clear(); Console.WriteLine("1. Вывести список студентов"); Console.WriteLine("2. Создать нового студента"); Console.WriteLine("3. Добавить экзамен студенту"); Console.WriteLine("4. Просмотр формы обучения студента"); Console.WriteLine("5. Просмотр экзаменов студента"); Console.WriteLine("6. Замер времени расчета массивов"); Console.WriteLine("7. Выход"); Console.WriteLine(); Console.Write("Выбирите пункт: "); int Menu = Convert.ToInt32(Console.ReadLine()); switch (Menu) { case 1: { // Вывод всех студентов Console.Clear(); if (Cheloveki.Count == 0) { Console.WriteLine("Список пуст"); Console.ReadKey(); break; } else { for (int i = 0; i < Cheloveki.Count; i++) { Console.WriteLine(i + ": " + Cheloveki[i].ToShortString()); } Console.WriteLine(); Console.WriteLine("Для перехода в меню нажмите любую клавишу"); Console.ReadKey(); break; } } case 2: { //Создание нового студента Console.Clear(); Console.Write("Введите имя: "); string name = Console.ReadLine(); Console.Write("Введите Фамилию: "); string surname = Console.ReadLine(); Console.Write("Год рождения: "); int year = Convert.ToInt32(Console.ReadLine()); Console.Write("Месяц рождения: "); int month = Convert.ToInt32(Console.ReadLine()); Console.Write("День рождения: "); int day = Convert.ToInt32(Console.ReadLine()); Console.Clear(); Console.WriteLine("Формы обучения: "); Console.WriteLine("1. Specialist"); Console.WriteLine("2. Вachelor"); Console.WriteLine("3. SecondEducation"); Console.Write("Выбирите форму обучения: "); int formEd = Convert.ToInt32(Console.ReadLine()); Console.Clear(); Console.Write("Введите номер группы: "); int nomGr = Convert.ToInt32(Console.ReadLine()); Console.Clear(); Cheloveki.Add(new Student(new Person(name, surname, new DateTime(year, month, day)), (Education)formEd, nomGr)); Console.WriteLine("Новый студент: " + Cheloveki[Cheloveki.Count - 1].ToString()); Console.WriteLine(); Console.ReadKey(); break; } case 3: { //Добавление экзамена студентам List<Exam> ListEx = new List<Exam>(); Console.Clear(); for (int i = 0; i < Cheloveki.Count; i++) { Console.WriteLine(i + ": " + Cheloveki[i].ToShortString()); } Console.WriteLine(); Console.Write("Выбирите студента: "); int nomStud = Convert.ToInt32(Console.ReadLine()); Console.Clear(); Console.WriteLine(Cheloveki[nomStud].ToString()); Console.WriteLine(); while (true) { Console.WriteLine(); Console.Write("Добавить/выход ?: "); if (Console.ReadLine() == "выход") { break; } else { Console.Write("Название предмета:"); string nameIt = Console.ReadLine(); Console.Write("Оценка:"); int mark = Convert.ToInt32(Console.ReadLine()); Console.Write("Год сдачи: "); int year = Convert.ToInt32(Console.ReadLine()); Console.Write("Месяц сдачи: "); int month = Convert.ToInt32(Console.ReadLine()); Console.Write("День сдачи: "); int day = Convert.ToInt32(Console.ReadLine()); ListEx.Add(new Exam(nameIt, mark, new DateTime(year, month, day))); Cheloveki[nomStud].AddExams(); } } Cheloveki[nomStud].AddExams(ListEx.ToArray()); Console.WriteLine(Cheloveki[nomStud].ToString()); Console.WriteLine(); Console.ReadKey(); break; } case 4: { //Просмотр формы обучения Console.Clear(); for (int i = 0; i < Cheloveki.Count; i++) { Console.WriteLine(i + ": " + Cheloveki[i].ToShortString()); } Console.WriteLine(); Console.Write("Выбирите студента: "); int nomStud = Convert.ToInt32(Console.ReadLine()); Console.Clear(); Console.WriteLine(Cheloveki[nomStud].ToString()); Console.WriteLine(); Console.WriteLine("Specialist: " + Cheloveki[nomStud][SomeEd1]); Console.WriteLine("Вachelor: " + Cheloveki[nomStud][SomeEd2]); Console.WriteLine("SecondEducation: " + Cheloveki[nomStud][SomeEd3]); Console.WriteLine(); Console.WriteLine("Для перехода в меню нажмите любую клавишу"); Console.ReadKey(); break; } case 5: { //Просмотр списка экзаменов Console.Clear(); for (int i = 0; i < Cheloveki.Count; i++) { Console.WriteLine(i + ": " + Cheloveki[i].ToShortString()); } Console.WriteLine(); Console.Write("Выбирите студента: "); int nomStud = Convert.ToInt32(Console.ReadLine()); Console.Clear(); Console.WriteLine(Cheloveki[nomStud].ToString()); Console.WriteLine(); for (int i = 0; i < Cheloveki[nomStud].FieldListExam.Length; i++) { Console.WriteLine(string.Format("Название:{0} Оценка:{1} Дата:{2} ", Cheloveki[nomStud].FieldListExam[i].NameItem, Cheloveki[nomStud].FieldListExam[i].Mark, Convert.ToString(Cheloveki[nomStud].FieldListExam[i].DateExam))); } Console.WriteLine(); Console.WriteLine("Для перехода в меню нажмите любую клавишу"); Console.ReadKey(); break; } case 6: { //Скорость отработки разных массивов Console.Clear(); Console.Write("Введите размерность: "); int n = Convert.ToInt32(Console.ReadLine()); MassTime t = new MassTime(n); Console.WriteLine("Время работы: "); Console.WriteLine("Одномерный массив: " + t.Timefirst()); Console.WriteLine("Двумерный массив: " + t.TimeRec()); Console.WriteLine("Двумерный ступеньчатый массив: " + t.TimedoSt()); Console.WriteLine(); Console.WriteLine("Для перехода в меню нажмите любую клавишу"); Console.ReadKey(); break; } case 7: { work = false; break; } } } }
static void Main(string[] args) { var person = new Person(); var patient = new Patient(); }
public Student(Person stud, Education formEd, int group) { Stud = stud; FormEd = formEd; Group = group; }
public Student() { Stud = new Person(); FormEd = (Education)1; Group = 21; }