Студопедия — Exercise 1: The first task in this exercise explains how to open Visual Studio and create a new project.
Студопедия Главная Случайная страница Обратная связь

Разделы: Автомобили Астрономия Биология География Дом и сад Другие языки Другое Информатика История Культура Литература Логика Математика Медицина Металлургия Механика Образование Охрана труда Педагогика Политика Право Психология Религия Риторика Социология Спорт Строительство Технология Туризм Физика Философия Финансы Химия Черчение Экология Экономика Электроника

Exercise 1: The first task in this exercise explains how to open Visual Studio and create a new project.






Exercise 2:

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace NewLanguageFeatures

{

public class Customer

{

public int CustomerID { get; private set; }

public string Name { get; set; }

public string City { get; set; }

 

public Customer(int ID)

{

CustomerID = ID;

}

 

public override string ToString()

{

return Name + "\t" + City + "\t" + CustomerID;

}

}

 

class Program

{

static void Main(string[] args)

{

Customer c = new Customer(1);

c.Name = "Maria Anders";

c.City = "Berlin";

 

Console.WriteLine(c);

}

 

}

}


Exercise 3:

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace NewLanguageFeatures

{

public class Customer

{

public int CustomerID { get; private set; }

public string Name { get; set; }

public string City { get; set; }

 

public Customer(int ID)

{

CustomerID = ID;

}

 

public override string ToString()

{

return Name + "\t" + City + "\t" + CustomerID;

}

}

 

class Program

{

 

static void Main(string[] args)

{

List<Customer> customers = CreateCustomers();

 

Console.WriteLine("Customers:\n");

foreach (Customer c in customers)

Console.WriteLine(c);

}

 

static List<Customer> CreateCustomers()

{

return new List<Customer>

{

new Customer(1) { Name = "Maria Anders", City = "Berlin" },

new Customer(2) { Name = "Laurence Lebihan", City = "Marseille" },

new Customer(3) { Name = "Elizabeth Brown", City = "London" },

new Customer(4) { Name = "Ann Devon", City = "London" },

new Customer(5) { Name = "Paolo Accorti", City = "Torino" },

new Customer(6) { Name = "Fran Wilson", City = "Portland" },

new Customer(7) { Name = "Simon Crowther", City = "London" },

new Customer(8) { Name = "Liz Nixon", City = "Portland" }

};

}

}

}

 


Exercise 4:

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace NewLanguageFeatures

{

public class Customer

{

public int CustomerID { get; private set; }

public string Name { get; set; }

public string City { get; set; }

 

public Customer(int ID)

{

CustomerID = ID;

}

 

public override string ToString()

{

return Name + "\t" + City + "\t" + CustomerID;

}

}

 

class Program

{

static void Main(string[] args)

{

List<Customer> customers = CreateCustomers();

 

Console.WriteLine("Customers:\n");

foreach (Customer c in customers)

Console.WriteLine(c);

}

 

static List<Customer> CreateCustomers()

{

return new List<Customer>

{

new Customer(1) { Name = "Maria Anders", City = "Berlin" },

new Customer(2) { Name = "Laurence Lebihan", City = "Marseille" },

new Customer(3) { Name = "Elizabeth Brown", City = "London" },

new Customer(4) { Name = "Ann Devon", City = "London" },

new Customer(5) { Name = "Paolo Accorti", City = "Torino" },

new Customer(6) { Name = "Fran Wilson", City = "Portland" },

new Customer(7) { Name = "Simon Crowther", City = "London" },

new Customer(8) { Name = "Liz Nixon", City = "Portland" }

};

}

}

}


Exercise 5:

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace NewLanguageFeatures

{

public static class Extensions

{

public static List<T> Append<T>(this List<T> a, List<T> b)

{

var newList = new List<T>(a);

newList.AddRange(b);

return newList;

}

 

public static bool Compare(this Customer customer1, Customer customer2)

{

if (customer1.CustomerID == customer2.CustomerID &&

customer1.Name == customer2.Name &&

customer1.City == customer2.City)

{

return true;

}

return false;

}

}

 

public class Customer

{

public int CustomerID { get; private set; }

public string Name { get; set; }

public string City { get; set; }

 

public Customer(int ID)

{

CustomerID = ID;

}

 

public override string ToString()

{

return Name + "\t" + City + "\t" + CustomerID;

}

}


class Program

{

static void Main(string[] args)

{

var customers = CreateCustomers();

 

var addedCustomers = new List<Customer>

{

new Customer(9) { Name = "Paolo Accorti", City = "Torino" },

new Customer(10) { Name = "Diego Roel", City = "Madrid" }

};

 

var updatedCustomers = customers.Append(addedCustomers);

 

var newCustomer = new Customer(10)

{

Name = "Diego Roel",

City = "Madrid"

};

 

foreach (var c in updatedCustomers)

{

if (newCustomer.Compare(c))

{

Console.WriteLine("The new customer was already in the list");

return;

}

}

Console.WriteLine("The new customer was not in the list");

}

 

static List<Customer> CreateCustomers()

{

return new List<Customer>

{

new Customer(1) { Name = "Maria Anders", City = "Berlin" },

new Customer(2) { Name = "Laurence Lebihan", City = "Marseille" },

new Customer(3) { Name = "Elizabeth Brown", City = "London" },

new Customer(4) { Name = "Ann Devon", City = "London" },

new Customer(5) { Name = "Paolo Accorti", City = "Torino" },

new Customer(6) { Name = "Fran Wilson", City = "Portland" },

new Customer(7) { Name = "Simon Crowther", City = "London" },

new Customer(8) { Name = "Liz Nixon", City = "Portland" }

};

}

}

}


Exercise 6:

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace NewLanguageFeatures

{

public static class Extensions

{

public static List<T> Append<T>(this List<T> a, List<T> b)

{

var newList = new List<T>(a);

newList.AddRange(b);

return newList;

}

 

public static bool Compare(this Customer customer1, Customer customer2)

{

if (customer1.CustomerID == customer2.CustomerID &&

customer1.Name == customer2.Name &&

customer1.City == customer2.City)

{

return true;

}

return false;

}

}

 

public class Customer

{

public int CustomerID { get; private set; }

public string Name { get; set; }

public string City { get; set; }

 

public Customer(int ID)

{

CustomerID = ID;

}

 

public override string ToString()

{

return Name + "\t" + City + "\t" + CustomerID;

}

}

 

class Program

{

static void Main(string[] args)

{

var customers = CreateCustomers();

 

foreach (var c in FindCustomersByCity(customers, "London"))

Console.WriteLine(c);

}

 

public static List<Customer> FindCustomersByCity(

List<Customer> customers,

string city)

{

return customers.FindAll(c => c.City == city);

}

 

static List<Customer> CreateCustomers()

{

return new List<Customer>

{

new Customer(1) { Name = "Maria Anders", City = "Berlin" },

new Customer(2) { Name = "Laurence Lebihan", City = "Marseille" },

new Customer(3) { Name = "Elizabeth Brown", City = "London" },

new Customer(4) { Name = "Ann Devon", City = "London" },

new Customer(5) { Name = "Paolo Accorti", City = "Torino" },

new Customer(6) { Name = "Fran Wilson", City = "Portland" },

new Customer(7) { Name = "Simon Crowther", City = "London" },

new Customer(8) { Name = "Liz Nixon", City = "Portland" }

};

}

}

}

 


Exercise 7:

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Linq.Expressions;

 

namespace NewLanguageFeatures

{

public static class Extensions

{

public static List<T> Append<T>(this List<T> a, List<T> b)

{

var newList = new List<T>(a);

newList.AddRange(b);

return newList;

}

 

public static bool Compare(this Customer customer1, Customer customer2)

{

if (customer1.CustomerID == customer2.CustomerID &&

customer1.Name == customer2.Name &&

customer1.City == customer2.City)

{

return true;

}

return false;

}

}

 

public class Customer

{

public int CustomerID { get; private set; }

public string Name { get; set; }

public string City { get; set; }

 

public Customer(int ID)

{

CustomerID = ID;

}

 

public override string ToString()

{

return Name + "\t" + City + "\t" + CustomerID;

}

}

 

class Program

{

static void Main(string[] args)

{

Func<int, int> addOne = n => n + 1;

Console.WriteLine("Result: {0}", addOne(5));

 

Expression<Func<int, int>> addOneExpression = n => n + 1;

 

var addOneFunc = addOneExpression.Compile();

Console.WriteLine("Result: {0}", addOneFunc(5));

}

 

public static List<Customer> FindCustomersByCity(

List<Customer> customers,

string city)

{

return customers.FindAll(c => c.City == city);

}

 

static List<Customer> CreateCustomers()

{

return new List<Customer>

{

new Customer(1) { Name = "Maria Anders", City = "Berlin" },

new Customer(2) { Name = "Laurence Lebihan", City = "Marseille" },

new Customer(3) { Name = "Elizabeth Brown", City = "London" },

new Customer(4) { Name = "Ann Devon", City = "London" },

new Customer(5) { Name = "Paolo Accorti", City = "Torino" },

new Customer(6) { Name = "Fran Wilson", City = "Portland" },

new Customer(7) { Name = "Simon Crowther", City = "London" },

new Customer(8) { Name = "Liz Nixon", City = "Portland" }

};

}

}

}

 


Exercise 8:

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Linq.Expressions;

 

namespace NewLanguageFeatures

{

public static class Extensions

{

public static List<T> Append<T>(this List<T> a, List<T> b)

{

var newList = new List<T>(a);

newList.AddRange(b);

return newList;

}

 

public static bool Compare(this Customer customer1, Customer customer2)

{

if (customer1.CustomerID == customer2.CustomerID &&

customer1.Name == customer2.Name &&

customer1.City == customer2.City)

{

return true;

}

return false;

}

}

 

public class Store

{

public string Name { get; set; }

public string City { get; set; }

 

public override string ToString()

{

return Name + "\t" + City;

}

}

public class Customer

{

public int CustomerID { get; private set; }

public string Name { get; set; }

public string City { get; set; }

 

public Customer(int ID)

{

CustomerID = ID;

}

 

public override string ToString()

{

return Name + "\t" + City + "\t" + CustomerID;

}

}

 

class Program

{

static void Query()

{

var stores = CreateStores();

var numLondon = stores.Count(s => s.City == "London");

Console.WriteLine("There are {0} stores in London. ", numLondon);

}

 

static void Main(string[] args)

{

Query();

}

 

public static List<Customer> FindCustomersByCity(

List<Customer> customers,

string city)

{

return customers.FindAll(c => c.City == city);

}

 

static List<Store> CreateStores()

{

return new List<Store>

{

new Store { Name = "Jim’s Hardware", City = "Berlin" },

new Store { Name = "John’s Books", City = "London" },

new Store { Name = "Lisa’s Flowers", City = "Torino" },

new Store { Name = "Dana’s Hardware", City = "London" },

new Store { Name = "Tim’s Pets", City = "Portland" },

new Store { Name = "Scott’s Books", City = "London" },

new Store { Name = "Paula’s Cafe", City = "Marseille" }

};

}

static List<Customer> CreateCustomers()

{

return new List<Customer>

{

new Customer(1) { Name = "Maria Anders", City = "Berlin" },

new Customer(2) { Name = "Laurence Lebihan", City = "Marseille" },

new Customer(3) { Name = "Elizabeth Brown", City = "London" },

new Customer(4) { Name = "Ann Devon", City = "London" },

new Customer(5) { Name = "Paolo Accorti", City = "Torino" },

new Customer(6) { Name = "Fran Wilson", City = "Portland" },

new Customer(7) { Name = "Simon Crowther", City = "London" },

new Customer(8) { Name = "Liz Nixon", City = "Portland" }

};

}

}

}

 

 







Дата добавления: 2015-09-07; просмотров: 363. Нарушение авторских прав; Мы поможем в написании вашей работы!



Композиция из абстрактных геометрических фигур Данная композиция состоит из линий, штриховки, абстрактных геометрических форм...

Важнейшие способы обработки и анализа рядов динамики Не во всех случаях эмпирические данные рядов динамики позволяют определить тенденцию изменения явления во времени...

ТЕОРЕТИЧЕСКАЯ МЕХАНИКА Статика является частью теоретической механики, изучающей условия, при ко­торых тело находится под действием заданной системы сил...

Теория усилителей. Схема Основная масса современных аналоговых и аналого-цифровых электронных устройств выполняется на специализированных микросхемах...

Тема: Составление цепи питания Цель: расширить знания о биотических факторах среды. Оборудование:гербарные растения...

В эволюции растений и животных. Цель: выявить ароморфозы и идиоадаптации у растений Цель: выявить ароморфозы и идиоадаптации у растений. Оборудование: гербарные растения, чучела хордовых (рыб, земноводных, птиц, пресмыкающихся, млекопитающих), коллекции насекомых, влажные препараты паразитических червей, мох, хвощ, папоротник...

Типовые примеры и методы их решения. Пример 2.5.1. На вклад начисляются сложные проценты: а) ежегодно; б) ежеквартально; в) ежемесячно Пример 2.5.1. На вклад начисляются сложные проценты: а) ежегодно; б) ежеквартально; в) ежемесячно. Какова должна быть годовая номинальная процентная ставка...

Вопрос. Отличие деятельности человека от поведения животных главные отличия деятельности человека от активности животных сводятся к следующему: 1...

Расчет концентрации титрованных растворов с помощью поправочного коэффициента При выполнении серийных анализов ГОСТ или ведомственная инструкция обычно предусматривают применение раствора заданной концентрации или заданного титра...

Психолого-педагогическая характеристика студенческой группы   Характеристика группы составляется по 407 группе очного отделения зооинженерного факультета, бакалавриата по направлению «Биология» РГАУ-МСХА имени К...

Studopedia.info - Студопедия - 2014-2024 год . (0.009 сек.) русская версия | украинская версия