.dll = Class Library (C# .NET Framework) (Project) .exe = Console App / Win Forms etc. (Project) (har PRÆCIS een Main method)
Visual Studio:
Solution .sln (Den vi typisk åbner) -blot en container
Indeholder projekt(er) .csproj
automatic using (and other tooltips) (CRTL + .)
Run all Tests
(CTRL + r) a
Extensions (Add methods to existing classes)
public static class GeneralExtensions
{
public static string Reverse(this string input)
{
}
}
- Create new C# Console App
- Console.Writeline Hello World
- Build test in powershell
Extension that can Print both an array string[] and a List
Hint: Use IEnumable
- Create a new console App Project
- Create a class library
- Create a test project for the class library
Examine existing solutions! Only 1 solution with three projects
-
In the class library make a Models folder
-
Make an interface IPerson (Name, Age, Hobby)
-
Make two classes (Child and Adult) both has to implement the IPerson interface
-
Make an extension method for IEnumable called Print (The method should return all names delimited by a comma (string not void as return)) -> Morten, Lærke -> Good for unit-testing
-
In the console App Create both an Array and a List with people and Console.Writeline the result from Print to the Console
string connectionString = @"Server=WIN-IE5HKVPLVKT;Database=Test;Integrated Security=True;";
SqlConnection connection = new SqlConnection(connectionString);
connection.Open();
string sql = @"
select
*
from
dbo.Sports;
";
IEnumerable<Sport> sports = connection
.Query<Sport>(sql)
.Where(sp => sp.NumberOfPlayers > 5);
create table dbo.Sports (
Id int identity(1,1) primary key,
[Name] varchar(50),
NumberofPlayers int,
HasBall bit --Boolean in SQL world!!
)
- Create a new Solution
- Create two projects (One Class Library .DLL (no entry point (main))) and one Console App (Has entry point)
- Make a Models folder in the class library
- Create class(es) (Worker, Employee and Employer) (The two latter inherits a Worker)
- Create approx. 7-10 Properties and some Methods (Age calculated, RaiseSalary())
- Use the classes in your Console App (Reference needed)
- Create three SQL Tables (Worker, Employee and Employer) (Foreign keys) (Join in select)
- Use Dapper
- Populate all Employees and Employer using Dapper (con.Query) and use foreach to very that all fields and all rows are shown
- Try mics. LINQ (Where, OrderBy...)
Worker (Name, DOB, Salary)
1 Morten
2 Lærke
Employee
1 Salary F
Employeer
2 Bonus
select *
from employer
inner join
worker
on ((ID = ID))
--> Name, DOB, Salary, Bonus