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 NumbersTest/NumbersTest/NumbersTest.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}") = "NumbersTest", "NumbersTest\NumbersTest.csproj", "{408EA78E-1721-4604-85CC-08B454FA2E3B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{408EA78E-1721-4604-85CC-08B454FA2E3B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{408EA78E-1721-4604-85CC-08B454FA2E3B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{408EA78E-1721-4604-85CC-08B454FA2E3B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{408EA78E-1721-4604-85CC-08B454FA2E3B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9E1D9868-8CBD-46CF-854B-B2788774905B}
EndGlobalSection
EndGlobal
8 changes: 8 additions & 0 deletions NumbersTest/NumbersTest/NumbersTest/NumbersTest.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 NumbersTest/NumbersTest/NumbersTest/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
namespace Session03Numbers
{
using System;
using System.Globalization;

namespace Session03Exercise02
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Ange ett antal siffror, separat med kommatecken");

var input = Console.ReadLine();

var inputArray = input.Split(",", StringSplitOptions.RemoveEmptyEntries);
double[] numberArray = new double[inputArray.Length];

for (int i = 0; i < inputArray.Length; i++)
{
NumberStyles numberStyles=NumberStyles.Integer

try
{
numberArray[i] = Convert.ToDouble(inputArray[i]);
}

catch (Exception)
{
numberArray[i] = 0;
}

/*/ finally Körs alltid ovasett vad som händer med koden
* Måste vara i en loop /*/

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.

Try... catch... finally kan man köra i vilken del av koden som helst.

{

}
/*/throw new Exception("Provocerat fel") Är ett egenskapat fel/*/

foreach (var number in numberArray)
{
Console.WriteLine("Värde: " + number.ToString());
}
static double GetDoubleValue(string input)
{
try
{
var result = int.Parse(input);

return result;
}
catch (FormatException ex) when (ex.Message.Contains("Input string"))
{
return double.MinValue;
}
catch (Exception ex)
{
return 0;
}
}



}
}

}
}
}


31 changes: 31 additions & 0 deletions Ny mapp/Session03Exercise01/Session03Exercise01.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

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}") = "Session03Exercise01", "Session03Exercise01\Session03Exercise01.csproj", "{1DA37EB2-8B33-4F46-9531-0BF485D85D43}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Session03Exercise02", "Session03Exercise02\Session03Exercise02.csproj", "{4EC32C31-2B0E-43AF-AF81-0AE8350D391A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{1DA37EB2-8B33-4F46-9531-0BF485D85D43}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1DA37EB2-8B33-4F46-9531-0BF485D85D43}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1DA37EB2-8B33-4F46-9531-0BF485D85D43}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1DA37EB2-8B33-4F46-9531-0BF485D85D43}.Release|Any CPU.Build.0 = Release|Any CPU
{4EC32C31-2B0E-43AF-AF81-0AE8350D391A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4EC32C31-2B0E-43AF-AF81-0AE8350D391A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4EC32C31-2B0E-43AF-AF81-0AE8350D391A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4EC32C31-2B0E-43AF-AF81-0AE8350D391A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C3302251-CC54-46F8-8F3E-6513ADE2B657}
EndGlobalSection
EndGlobal
40 changes: 40 additions & 0 deletions Ny mapp/Session03Exercise01/Session03Exercise01/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;

namespace Session03Exercise01
{
class Program
{
static void Main(string[] args)
{
int[] integerValues = new [] { 1, 2, 3 };
var integerValueName = nameof(integerValues);

for (var i = 0; i < integers.Length; i++)
{
var name = nameof(integers);
var value = integers[i];

Console.WriteLine($"Index {i} i arrayen {nameof(integers)} har värdet: {integers[i]}");
}
var doWhileIndex = 0;

do
{
var value = integerValues[doWhileIndex];

Console.WriteLine($"Index{doWhileIndex} i arrayen {integerValueName} har värdet: {value}");
doWhileIndex++;
}
while (doWhileIndex < integerValues.Length);

var whileIndex = 0;

while (whileIndex++ < integersValues < whileIndex)

Console.WriteLine($"While Index {whileIndex} i arrayen {integerValueName} har värdet: {value}");

whileIndex++;

}
}
}
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>
21 changes: 21 additions & 0 deletions Ny mapp/Session03Exercise01/Session03Exercise02/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;

namespace Session03Exercise02
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Ange ett antal siffror, separat med kommatecken");

var input = Console.ReadLine();

var inputArray = input.Split(",", StringSplitOptions.RemoveEmptyEntries);

foreach (var number in inputArray)
{
Console.WriteLine("Värdet är " + number);
}
}
}
}
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>
95 changes: 95 additions & 0 deletions Session02/Session02Example01/Session02Example01/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
using System;
using System.Xml.Schema;

namespace Session02Example01
{
class Program
{
static void Main(string[] args)
{
// Binary operation
var additionResult = 1 + 2;

Console.WriteLine("additionalResult " + additionResult.ToString());

var incrementResult = ++additionResult;

Console.WriteLine("incrementResult " + incrementResult.ToString());

var trueValue = true;

var falseValue = false;

var andResult = trueValue & falseValue; // 0b0110
var orResult = trueValue | falseValue;
var xorResult = trueValue ^ falseValue;

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

var moduloResult = 7 % 5;

Console.WriteLine("moduloResult " + moduloResult);

var highInteger = 1000;
var IntegerDivisionResult = highInteger / 3;

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

Console.WriteLine("integerDivisionResult " + IntegerDivisionResult);
Console.WriteLine("doubleDivisionResult " + doubleDivisionResult);

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

Console.WriteLine("castIntDivisionResults " + castIntDivisionResult);

var conversionResult = Convert.ToInt32(doubleDivisionResult);

Console.WriteLine("convertionResult " + conversionResult);

var midpointDivisionResult = 10.0 / 3.0;

Console.WriteLine("midpointDivisionResult " + midpointDivisionResult);
Console.WriteLine("castToInt " + ((int)midpointDivisionResult).ToString());

Console.WriteLine("ceiling " +Math.Ceiling(midpointDivisionResult));
Console.WriteLine("floor " + Math.Floor(midpointDivisionResult));
Console.WriteLine("round " + Math.Round(midpointDivisionResult));
// Med decimaler
Console.WriteLine("round " + Math.Round(midpointDivisionResult,3));


additionResult += 2;
additionResult -= 2;
additionResult /= 2;
additionResult *= 2;

//^^ Smidigare sätt än det nedanför. Gör samma sak

additionResult = additionResult + 2;

var greaterResult = 5 > 3;
var lessThanResult = 5 < 3;
var greaterOrEqual = 5 >= 3;
var lessOrEqual = 5 <= 3;

Console.WriteLine("greaterResult " + greaterResult);
Console.WriteLine("lessThanResult " + lessThanResult);
Console.WriteLine("greaterOrEqual " + greaterOrEqual);
Console.WriteLine("lessOrEqual " + lessOrEqual);

var andOperationResult = true && false;
var orOperationalResult = false || true;

Console.WriteLine("andOperationalResult " + andOperationResult);
Console.WriteLine("orOperationalResult " + orOperationalResult);



Console.ReadKey();

}
}
}
29 changes: 29 additions & 0 deletions Session02/Session02Example02/Session02Example02/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;

namespace Session02Example02
{
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 även jättegammal");
}
}
}
}
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>
35 changes: 35 additions & 0 deletions Session02/Session02Example03/Session02Example03/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;

namespace Session02Example03
{
class Program
{
static void Main(string[] args)
{
var input = Console.ReadLine();
var integer = Convert.ToInt32(input);

string waterLabel = integer >= 27 ? "Går bra att bada" : "Går inte att bada";

/*/if(integer >27)
{
waterLabel = "Går bra att bada";
}
else
{
waterLabel = "Går inte bra att bada";
}
/*/

//Om det är dessa exakta värden inträffar
switch (integer)
{
case 1: waterLabel = "Går inte bra att bada alls"; break;
case 3-: waterLabel = "Det är 3 minusgrader"; break;
default: /*Här kan man göra något om inget träffar*/ 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>
Loading