Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Session02/ConsoleApp1/ConsoleApp1.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30413.136
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp1", "ConsoleApp1\ConsoleApp1.csproj", "{0CDB9C9E-2F2C-4E95-9761-DA19DB872C5D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0CDB9C9E-2F2C-4E95-9761-DA19DB872C5D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0CDB9C9E-2F2C-4E95-9761-DA19DB872C5D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0CDB9C9E-2F2C-4E95-9761-DA19DB872C5D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0CDB9C9E-2F2C-4E95-9761-DA19DB872C5D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4025A1B4-422B-40C7-9624-54D828A1EA67}
EndGlobalSection
EndGlobal
8 changes: 8 additions & 0 deletions Session02/ConsoleApp1/ConsoleApp1/ConsoleApp1.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

</Project>
40 changes: 40 additions & 0 deletions Session02/ConsoleApp1/ConsoleApp1/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;

namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
var integerValues = new[] { 1, 2, 3 };
var name = nameof(integerValues);
Console.WriteLine("For-loop");
for (var i = 0; i < integerValues.Length; i++)
{
var value = integerValues[i];

Console.WriteLine($"Index {i} i arrayen {name} har värdet: {value}");
}
Console.WriteLine();
Console.WriteLine("Do-while-loop");
var doWhileIndex = 0;
do
{
var value = integerValues[doWhileIndex];
Console.WriteLine($"Index {doWhileIndex} i arrayen {name} har värdet: {value}");
doWhileIndex++;
}
while (doWhileIndex < integerValues.Length);

var whileIndex = 0;
Console.WriteLine();
Console.WriteLine("While-loop");
while(whileIndex < integerValues.Length)
{
var value = integerValues[whileIndex];
Console.WriteLine($"Index {whileIndex} i arrayen {name} har värdet: {value}");
whileIndex++;
}
Comment on lines +9 to +37

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Denna kod skulle må bra av lite tomma rader. Prova att lägga in en före och efter varje Console.Write som ligger utanför kodblock.

var integerValues = new[] { 1, 2, 3 };
var name = nameof(integerValues);

Console.WriteLine("For-loop");

for (var i = 0; i < integerValues.Length; i++)

}
}
}
8 changes: 8 additions & 0 deletions Session02/Session02/ConsoleApp1/ConsoleApp1.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

</Project>
71 changes: 71 additions & 0 deletions Session02/Session02/ConsoleApp1/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using System;

namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
var additionResult = 1 + 2;
Console.WriteLine("Additionresult: " + additionResult);
var incrementResult1 = additionResult++;
var incrementResult2 = ++additionResult;
Console.WriteLine("incrementresult: " + incrementResult1);
Console.WriteLine("incrementresult: " + incrementResult2);

var trueValue = true;
var falseValue = false;

// Inte boolsk jämförelse
var andResult = 0b0010 & 0b0100; // 0b0110
var orResult = trueValue | falseValue;
var xorResult = trueValue ^ falseValue;

Console.WriteLine("andResult: " + andResult);
Console.WriteLine("orResult: " + orResult);
Console.WriteLine("xorValue: " + xorResult);

var moduleResult = 3 % 2;

Console.WriteLine("ModuleResult: " + moduleResult);

var highInteger = 1000;
var divisionResult = highInteger / 3;
// Implicit värdekonvertering till double
var doubleDivisionResult = highInteger / 3.0;

var forcedIntDivisionResult = (int)(highInteger / 3.0);

Console.WriteLine("DivisionResult: " + divisionResult);
Console.WriteLine("DoubleDivisionResult: " + doubleDivisionResult);
Console.WriteLine("forcedIntDivisionResult: " + forcedIntDivisionResult);

var conversionResult = Convert.ToInt32(doubleDivisionResult);
Console.WriteLine("conversionResult: " + conversionResult);

var midpointDivisionResult = 1.0 / 3.0;

Console.WriteLine("midpointDivisionResult: " + midpointDivisionResult);
Console.WriteLine("castToInt: " + ((int)midpointDivisionResult));
Console.WriteLine("Ceiling: " + Math.Ceiling(midpointDivisionResult));
Console.WriteLine("Floor: " + Math.Floor(midpointDivisionResult));
Console.WriteLine("Round: " + Math.Round(midpointDivisionResult, 3));

//Det går även att använda sammanslagna operatorer
// -=
// +=
// *=
// /=

// Finns även <=, >=, ==,
var greaterResult = 5 > 3;
var lessThanResult = 5 < 3;

Console.WriteLine("greaterThanREsult: " + greaterResult);
Console.WriteLine("lessThanResult: " + lessThanResult);



}
}
}
43 changes: 43 additions & 0 deletions Session02/Session02/Session02.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30413.136
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Session02Excercise01", "Session02Excercise01\Session02Excercise01.csproj", "{19876383-95F1-4AF9-AED1-87B1940C5CA4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Session02Exercise02", "Session02Exercise02\Session02Exercise02.csproj", "{B6BA7FFB-6B0D-4079-B268-2E00DA25480D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp1", "ConsoleApp1\ConsoleApp1.csproj", "{FABF555D-DB61-4EE6-AD9F-A6FC603412FB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Session02Example04", "Session02Example04\Session02Example04.csproj", "{18E7D114-46CA-494E-819B-031C8EC8420D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{19876383-95F1-4AF9-AED1-87B1940C5CA4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{19876383-95F1-4AF9-AED1-87B1940C5CA4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{19876383-95F1-4AF9-AED1-87B1940C5CA4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{19876383-95F1-4AF9-AED1-87B1940C5CA4}.Release|Any CPU.Build.0 = Release|Any CPU
{B6BA7FFB-6B0D-4079-B268-2E00DA25480D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B6BA7FFB-6B0D-4079-B268-2E00DA25480D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B6BA7FFB-6B0D-4079-B268-2E00DA25480D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B6BA7FFB-6B0D-4079-B268-2E00DA25480D}.Release|Any CPU.Build.0 = Release|Any CPU
{FABF555D-DB61-4EE6-AD9F-A6FC603412FB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FABF555D-DB61-4EE6-AD9F-A6FC603412FB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FABF555D-DB61-4EE6-AD9F-A6FC603412FB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FABF555D-DB61-4EE6-AD9F-A6FC603412FB}.Release|Any CPU.Build.0 = Release|Any CPU
{18E7D114-46CA-494E-819B-031C8EC8420D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{18E7D114-46CA-494E-819B-031C8EC8420D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{18E7D114-46CA-494E-819B-031C8EC8420D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{18E7D114-46CA-494E-819B-031C8EC8420D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {29AF081A-69D3-4EEB-A68C-563945E90467}
EndGlobalSection
EndGlobal
51 changes: 51 additions & 0 deletions Session02/Session02/Session02Example04/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;

namespace Session02Example04
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Ange ålder: ");
var input = Console.ReadLine();
var integer = Convert.ToInt32(input);

if (integer >= 18)
{
Console.WriteLine("Du får köpa tobaksprodukter");
}
else
{
Console.WriteLine("Du får inte köpa tobaksprodukter");
}

if (integer >= 40)
{
Console.WriteLine("Du är jättegammal");
}

Console.WriteLine("Ange vattentemperatur i grader C: ");
var input1 = Console.ReadLine();
var integer1 = Convert.ToInt32(input1);
Comment on lines +28 to +29

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Här skulle man helt enkelt kunna återanvända input och integer utan att skapa nya variabler.

input = Console.ReadLine();
integer = Convert.ToInt32(input);


string waterLabel = integer1 >= 27 ? "Går att bada" : "Går inte att bada";
//if (integer1 >= 27)
//{
//Console.WriteLine("Går att bada");
//}
//else
//{
// Console.WriteLine("Det går inte att bada");
//}

switch (integer1)
{
case 1: waterLabel = "Går inte att bada alls"; break;
case -3: waterLabel = "Det är 3 minusgrader"; break;
}
Console.WriteLine(waterLabel + " i havet");


}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

</Project>
18 changes: 18 additions & 0 deletions Session02/Session02/Session02Excercise01/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;

namespace Session02Excercise01
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");

var integer = 0;
string stringValue = "MyStringValue";

Console.WriteLine("Integer is " + integer.ToString());
Console.WriteLine("The value of stringValue is: " + stringValue);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

</Project>
22 changes: 22 additions & 0 deletions Session02/Session02/Session02Exercise02/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
namespace Session02Exercise02
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Do you want to enter your name? (y/n)!");
var key = Console.ReadKey();

if (key.KeyChar == 'n')
{
return;
}
Console.WriteLine("Enter your name:");
var name = Console.ReadLine();

Console.WriteLine("Hello, " + name);
Console.ReadKey();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

</Project>
23 changes: 23 additions & 0 deletions Session02/Session02ex02/Session02Exercise02/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;

namespace Session02Exercise02
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Do you want to enter your name? (y/n)!");
var key = Console.ReadKey();

if (key.KeyChar == 'n')
{
return;
}
Console.WriteLine("Enter your name:");
var name = Console.ReadLine();

Console.WriteLine("Hello, " + name);
Console.ReadKey();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

</Project>
25 changes: 25 additions & 0 deletions Session02/Session02ex02/Session02ex02.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30413.136
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Session02Exercise02", "Session02Exercise02\Session02Exercise02.csproj", "{B1019ED2-4FE5-428A-BBDE-C759C7A53C90}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B1019ED2-4FE5-428A-BBDE-C759C7A53C90}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B1019ED2-4FE5-428A-BBDE-C759C7A53C90}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B1019ED2-4FE5-428A-BBDE-C759C7A53C90}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B1019ED2-4FE5-428A-BBDE-C759C7A53C90}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {49EFCB3E-6855-4062-BC6E-F9B69B92A772}
EndGlobalSection
EndGlobal
Loading