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
2 changes: 1 addition & 1 deletion Database/Database.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">

Create Da
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
Expand Down
28 changes: 28 additions & 0 deletions Files/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/bin/Debug/netcoreapp2.0/Files.dll",
"args": [],
"cwd": "${workspaceFolder}",
// For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window
"console": "internalConsole",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
,]
}
15 changes: 15 additions & 0 deletions Files/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/Files.csproj"
],
"problemMatcher": "$msCompile"
}
]
}
32 changes: 32 additions & 0 deletions Files/Files.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.IO;

namespace Files
{
Expand All @@ -7,6 +8,37 @@ class Program
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
Createfile();
}
public static string Createfile()
{
string fileName = "This is a text file";
try
{
if (File.Exists(fileName))
{
File.Delete(fileName);
}
using (StreamWriter sw = File.CreateText(fileName))
{
sw.WriteLine("This is a text file");
}
using (StreamReader sr = File.OpenText(fileName))
{
string s = sr.ReadLine();
while (s != null)
{
Console.WriteLine(s);
s = sr.ReadLine();
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
return fileName;
}
}
}

1 change: 1 addition & 0 deletions Files/This is a text file
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is a text file
8 changes: 8 additions & 0 deletions Files2/Files2.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>netcoreapp2.2</TargetFramework>
</PropertyGroup>

</Project>
44 changes: 44 additions & 0 deletions Files2/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.IO;
using System.Collections.Generic;

namespace Files
{
class Program
{
static void Main(string[] args)
{
Random rnd = new Random();
int randNum;
List<string> text = new List<string>();
foreach (string word in File.ReadLines(@"C:\Users\Sam Mangum-Bostick\Documents\c#\csharp-workbook\Files2\words.txt"))
{
text.Add(word);
}
randNum = rnd.Next(0, text.Count);

string[] text2 = File.ReadAllLines(@"C:\Users\Sam Mangum-Bostick\Documents\c#\csharp-workbook\Files2\words.txt");
System.Console.WriteLine("The random word is {0}", text2[randNum]);

Console.WriteLine("Please enter a word to see if it comes before or after the random word");
string userWord = Console.ReadLine();
int wordPosition = text.FindIndex(w => userWord == w);
if (wordPosition == -1)
{
Console.WriteLine("What you enter is not a word!");
}
else if (wordPosition < randNum && wordPosition > -1)
{
Console.WriteLine("The word you entered comes before {0}.", text[randNum]);
}
else if (wordPosition > randNum)
{
Console.WriteLine("The word you entered comes before {0}.", text[randNum]);
}
else if (wordPosition == randNum)
{
Console.WriteLine("The word you entered is the same as the random word");
}
}
}
}
Loading