Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Numbers #10

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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/Session02.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}") = "Session02exercise01", "Session02exercise01\Session02exercise01.csproj", "{A6A2F41E-DEEC-4B02-81D0-B8172D365CA0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A6A2F41E-DEEC-4B02-81D0-B8172D365CA0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A6A2F41E-DEEC-4B02-81D0-B8172D365CA0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A6A2F41E-DEEC-4B02-81D0-B8172D365CA0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A6A2F41E-DEEC-4B02-81D0-B8172D365CA0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {07EFC3EA-3D86-4898-938C-0A6AD3D6F172}
EndGlobalSection
EndGlobal
20 changes: 20 additions & 0 deletions Session02/Session02exercise01/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;

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

var integer = 0;

Console.WriteLine("Integer is " + integer.ToString());

string stringValue = "MyStringValue";

Console.WriteLine("The value of stringValue is: " + stringValue);
}
}
}
8 changes: 8 additions & 0 deletions Session02/Session02exercise01/Session02exercise01.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>
19 changes: 19 additions & 0 deletions Session03/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;

namespace Session02Exercise02
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Ange ett antal siffror, separerat med kommatecken.");
var input = Console.ReadLine();
var inputArray = input.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

foreach (var number in inputArray)
{
Console.WriteLine("Värdet är " + number);
}
}
}
}
19 changes: 19 additions & 0 deletions Session03/Session 03.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;

namespace Session02Exercise02
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Ange ett antal siffror, separerat med kommatecken.");
var input = Console.ReadLine();
var inputArray = input.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

foreach (var number in inputArray)
{
Console.WriteLine("Värdet är " + number);
}
}
}
}
31 changes: 31 additions & 0 deletions Session03/Session03/Session03.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.30406.217
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Session03Excercise01", "Session03Excercise01\Session03Excercise01.csproj", "{BF0CB2FF-AAAD-46C4-B03B-44350686714D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Session03Excercise02", "Session03Excercise02\Session03Excercise02.csproj", "{01C8E8D9-978C-4691-BF80-020EB352DE0D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{BF0CB2FF-AAAD-46C4-B03B-44350686714D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BF0CB2FF-AAAD-46C4-B03B-44350686714D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BF0CB2FF-AAAD-46C4-B03B-44350686714D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BF0CB2FF-AAAD-46C4-B03B-44350686714D}.Release|Any CPU.Build.0 = Release|Any CPU
{01C8E8D9-978C-4691-BF80-020EB352DE0D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{01C8E8D9-978C-4691-BF80-020EB352DE0D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{01C8E8D9-978C-4691-BF80-020EB352DE0D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{01C8E8D9-978C-4691-BF80-020EB352DE0D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {D3E45702-2874-437E-922B-D41371BDC2CE}
EndGlobalSection
EndGlobal
43 changes: 43 additions & 0 deletions Session03/Session03/Session03Excercise01/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;

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

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

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

var doWhileIndex = 0;

do
{
var value = integerValues[doWhileIndex];

Console.WriteLine($"Do while Index {doWhileIndex} i arrayen {integerValuesName} har värdet: {value}");

doWhileIndex++;
}
while (doWhileIndex < integerValues.Length);

var whileIndex = 0;

while (whileIndex < integerValues.Length)
{
var value = integerValues[whileIndex];

Console.WriteLine($"While Index {whileIndex} i arrayen {integerValuesName} 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>
31 changes: 31 additions & 0 deletions Session03/Session03/Session03Excercise02/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Linq.Expressions;

namespace Exercise03
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Ange ett antal siffror, separerat med kommatecken.");
string input = Console.ReadLine();
string[] inputArray = input.Split(",", StringSplitOptions.RemoveEmptyEntries);
double?[] numberArray = new double?[inputArray.Length];

for (int i = 0; i < inputArray.Length; i++)
{
try
{
numberArray[i] = Convert.ToDouble(inputArray[i]);
}
catch (Exception)
{
numberArray[i] = null;
}
}

//Console.WriteLine("Värdet är " + number);
Copy link
Owner

Choose a reason for hiding this comment

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

Prova att göra klart denna övning.
Man behöver loopa igenom numberArray igen med en ytterligare for-loop.
Sedan behöver du hålla koll på minValue, maxValue, sum och count.
count skall inte ökas och sum skall inte adderas if (numberArray[i] == null)

Copy link
Owner

Choose a reason for hiding this comment

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

För att hoppa vidare i en for-loop kan man använda nyckelordet continue.
För att komma åt värdet av en nullbar double så behöver man skriva numberArray[i].Value


}
}
}
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>