Skip to content
15 changes: 15 additions & 0 deletions core/encoding/cyrillic-to-latin/cs/Common/Common.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
namespace CyrillicToLatin.Common
{
public static class Common
{
public const string NoSourceOrDestinationFile = "There must be a source and a destination file.";

public const string FileDoesntExist = "The source file does not exist.";

public const string WrongDirectory = "Invalid directory: {0}";

public const string WrongIO = "I/O exception: {0}";
}
}

13 changes: 8 additions & 5 deletions core/encoding/cyrillic-to-latin/cs/ConsoleModule.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System;
using System.IO;
using System.Security.AccessControl;
using System.Text;
using CyrillicToLatin.Common;


class ConsoleModule
{
Expand All @@ -9,9 +12,9 @@ static void Main()
string[] args = Environment.GetCommandLineArgs();

// Get command line arguments.
if (args.Length != 3 || String.IsNullOrWhiteSpace(args[1]) || String.IsNullOrWhiteSpace(args[2]))
if (args.Length != 3 || string.IsNullOrWhiteSpace(args[1]) || string.IsNullOrWhiteSpace(args[2]))
{
Console.WriteLine("There must be a source and a destination file.");
Console.WriteLine(Common.NoSourceOrDestinationFile);
ShowSyntax();
return;
}
Expand All @@ -21,7 +24,7 @@ static void Main()

if (!File.Exists(source))
{
Console.WriteLine("The source file does not exist.");
Console.WriteLine(Common.NoSourceOrDestinationFile);
return;
}

Expand Down Expand Up @@ -74,12 +77,12 @@ static void Main()
}
catch (DirectoryNotFoundException e)
{
Console.WriteLine($"Invalid directory: {e.Message}");
Console.WriteLine(Common.WrongDirectory);
return;
}
catch (IOException e)
{
Console.WriteLine($"I/O exception: {e.Message}");
Console.WriteLine(Common.WrongIO);
return;
}
}
Expand Down
6 changes: 6 additions & 0 deletions core/encoding/cyrillic-to-latin/cs/CyrillicToLatin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,10 @@
<PackageReference Include="System.Text.Encoding.CodePages" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
<None Remove="Common\" />
</ItemGroup>
<ItemGroup>
<Folder Include="Common\" />
</ItemGroup>
</Project>
10 changes: 5 additions & 5 deletions core/encoding/cyrillic-to-latin/cs/CyrillicToLatinFallback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

class CyrillicToLatinFallback : EncoderFallback
{
private Dictionary<Char, String> table;
private Dictionary<char, string> table;

public CyrillicToLatinFallback()
{
table = new Dictionary<Char, String>();
table = new Dictionary<char, string>();
// Define mappings.
// Uppercase modern Cyrillic characters.
table.Add('\u0410', "A");
Expand Down Expand Up @@ -92,12 +92,12 @@ public override int MaxCharCount

public class CyrillicToLatinFallbackBuffer : EncoderFallbackBuffer
{
private Dictionary<Char, String> table;
private Dictionary<char, string> table;
private int bufferIndex;
private string buffer;
private int leftToReturn;

internal CyrillicToLatinFallbackBuffer(Dictionary<Char, String> table)
internal CyrillicToLatinFallbackBuffer(Dictionary<char, string> table)
{
this.table = table;
this.bufferIndex = -1;
Expand Down Expand Up @@ -153,4 +153,4 @@ public override int Remaining
{
get { return leftToReturn; }
}
}
}
11 changes: 7 additions & 4 deletions csharp/classes-quickstart/BankAccount.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System;
using System.Collections.Generic;
using classes.Contracts;

namespace classes
{
public class BankAccount
public class BankAccount : IBank
{
public string Number { get; }
public string Number { get; set; }
public string Owner { get; set; }
#region BalanceComputation
public decimal Balance
Expand All @@ -21,6 +22,7 @@ public decimal Balance
return balance;
}
}

#endregion

private static int accountNumberSeed = 1234567890;
Expand All @@ -36,7 +38,8 @@ public BankAccount(string name, decimal initialBalance)
#endregion

#region TransactionDeclaration
private List<Transaction> allTransactions = new List<Transaction>();

private List<ITransaction> allTransactions = new List<ITransaction>();
#endregion

#region DepositAndWithdrawal
Expand Down Expand Up @@ -82,4 +85,4 @@ public string GetAccountHistory()
}
#endregion
}
}
}
14 changes: 14 additions & 0 deletions csharp/classes-quickstart/Contracts/IBank.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;

namespace classes.Contracts
{
public interface IBank
{
public string Number { get; }

public string Owner { get; }

public decimal Balance { get; }
}
}
12 changes: 12 additions & 0 deletions csharp/classes-quickstart/Contracts/ITransaction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
namespace classes.Contracts
{
public interface ITransaction
{
public decimal Amount { get; }

public DateTime Date { get; }

public string Notes { get; }
}
}
6 changes: 6 additions & 0 deletions csharp/classes-quickstart/classes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<None Remove="Contracts\" />
</ItemGroup>
<ItemGroup>
<Folder Include="Contracts\" />
</ItemGroup>
</Project>
9 changes: 5 additions & 4 deletions csharp/classes-quickstart/transaction.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using System;
using classes.Contracts;

namespace classes
{
public class Transaction
public class Transaction : ITransaction
{
public decimal Amount { get; }
public decimal Amount { get; set; }
public DateTime Date { get; }
public string Notes { get; }
public string Notes { get; set; }

public Transaction(decimal amount, DateTime date, string note)
{
Expand All @@ -15,4 +16,4 @@ public Transaction(decimal amount, DateTime date, string note)
this.Notes = note;
}
}
}
}
6 changes: 4 additions & 2 deletions csharp/events/VersionOne.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ public class FileSearcher

public void Search(string directory, string searchPattern)
{
foreach (var file in Directory.EnumerateFiles(directory, searchPattern))
var enumeratedFiles = Directory.EnumerateFiles(directory, searchPattern);

foreach (var file in enumeratedFiles)
{
FileFound?.Invoke(this, new FileFoundArgs(file));
}
}
}
}
23 changes: 7 additions & 16 deletions csharp/list-quickstart/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,16 @@ void WorkWithString()
Console.WriteLine($"The list has {names.Count} people in it");

var index = names.IndexOf("Felipe");
if (index == -1)
{
Console.WriteLine($"When an item is not found, IndexOf returns {index}");
}
else
{
Console.WriteLine($"The name {names[index]} is at index {index}");
}

Console.WriteLine(index == -1
? $"When an item is not found, IndexOf returns {index}"
: $"The name {names[index]} is at index {index}");

index = names.IndexOf("Not Found");
if (index == -1)
{
Console.WriteLine($"When an item is not found, IndexOf returns {index}");
}
else
{
Console.WriteLine($"The name {names[index]} is at index {index}");

}
Console.WriteLine(index == -1
? $"When an item is not found, IndexOf returns {index}"
: $"The name {names[index]} is at index {index}");

names.Sort();
foreach (var name in names)
Expand Down
4 changes: 2 additions & 2 deletions csharp/tutorials/exploration/csharp6-starter/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ public class Person

public Person(string first, string last)
{
FirstName = first;
LastName = last;
this.FirstName = first;
this.LastName = last;
}

public override string ToString()
Expand Down
10 changes: 5 additions & 5 deletions csharp/unit-testing/NUnit.TestProject/ByOrder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class ByOrder
public static bool Test3Called;

[Test, Order(5)]
public void Test1()
public void Should_Run_Last_After_Other_Tests_And_Validate_Previous_Execution_State()
{
Test3Called = true;

Expand All @@ -20,7 +20,7 @@ public void Test1()
}

[Test, Order(0)]
public void Test2B()
public void Should_Run_Second_After_First_Test_And_Validate_Only_First_Has_Run()
{
Test2BCalled = true;

Expand All @@ -30,7 +30,7 @@ public void Test2B()
}

[Test]
public void Test2A()
public void Should_Run_Third_When_No_Order_Is_Specified_And_All_Previous_Tests_Are_Called()
{
Test2ACalled = true;

Expand All @@ -40,7 +40,7 @@ public void Test2A()
}

[Test, Order(-5)]
public void Test3()
public void Should_Run_First_Before_All_Other_Tests_And_Ensure_No_Prior_Execution()
{
Test1Called = true;

Expand All @@ -49,4 +49,4 @@ public void Test3()
Assert.That(Test3Called is false);
}
}
}
}
Loading