C# port of Name

This commit is contained in:
Haydn Kane
2021-03-04 00:35:47 +00:00
parent ca285b4c18
commit dbfcc3dfc2
4 changed files with 118 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
</Project>

25
63 Name/csharp/Name.sln Normal file
View File

@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31005.135
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Name", "Name.csproj", "{B63B5D5C-C5E0-4EFE-9EF4-292915DCC22D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B63B5D5C-C5E0-4EFE-9EF4-292915DCC22D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B63B5D5C-C5E0-4EFE-9EF4-292915DCC22D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B63B5D5C-C5E0-4EFE-9EF4-292915DCC22D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B63B5D5C-C5E0-4EFE-9EF4-292915DCC22D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {FCD5BEAE-D35E-49A7-B8F3-B8B3F4A8C624}
EndGlobalSection
EndGlobal

44
63 Name/csharp/Program.cs Normal file
View File

@@ -0,0 +1,44 @@
using System;
namespace Name
{
public class Program
{
static void Main(string[] args)
{
Console.WriteLine("NAME".CentreAlign());
Console.WriteLine("CREATIVE COMPUTING MORRISTOWN, NEW JERSEY".CentreAlign());
Console.WriteLine();
Console.WriteLine();
Console.WriteLine();
Console.WriteLine("HELLO.");
Console.WriteLine("MY NAME IS CREATIVE COMPUTER.");
Console.Write("WHAT'S YOUR NAME (FIRST AND LAST? ");
var name = Console.ReadLine();
Console.WriteLine();
Console.WriteLine($"THANK YOU, {name.Reverse()}.");
Console.WriteLine("OOPS! I GUESS I GOT IT BACKWARDS. A SMART");
Console.WriteLine("COMPUTER LIKE ME SHOULDN'T MAKE A MISTAKE LIKE THAT!");
Console.WriteLine();
Console.WriteLine("BUT I JUST NOTICED YOUR LETTERS ARE OUT OF ORDER.");
Console.WriteLine($"LET'S PUT THEM IN ORDER LIKE THIS: {name.Sort()}");
Console.WriteLine();
Console.Write("DON'T YOU LIKE THAT BETTER? ");
var like = Console.ReadLine();
Console.WriteLine();
if (like.ToUpperInvariant() == "YES")
{
Console.WriteLine("I KNEW YOU'D AGREE!!");
}
else
{
Console.WriteLine("I'M SORRY YOU DON'T LIKE IT THAT WAY.");
}
Console.WriteLine();
Console.WriteLine($"I REALLY ENJOYED MEETING YOU {name}.");
Console.WriteLine("HAVE A NICE DAY!");
}
}
}

View File

@@ -0,0 +1,41 @@
using System;
namespace Name
{
public static class StringExtensions
{
private const int ConsoleWidth = 120; // default console width
public static string CentreAlign(this string value)
{
int spaces = ConsoleWidth - value.Length;
int leftPadding = spaces / 2 + value.Length;
return value.PadLeft(leftPadding).PadRight(ConsoleWidth);
}
public static string Reverse(this string value)
{
if (value is null)
{
return null;
}
char[] characterArray = value.ToCharArray();
Array.Reverse(characterArray);
return new String(characterArray);
}
public static string Sort(this string value)
{
if (value is null)
{
return null;
}
char[] characters = value.ToCharArray();
Array.Sort(characters);
return new string(characters);
}
}
}