Переделать код с++ в код с# - C#
Формулировка задачи:
Товарищи есть ли эксперты по переводу кода из с++ в с# ниже пишу код в с++
Очень надеюсь на код с комментариями для тупеньких заранее спасибо.
Нужна Программа, которая считывает текст из файла и выводит его на экран, заменив цифры от 0 до 9 на слова "ноль", "один",..."девять", начиная каждое предложение с новой строки
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <cctype>
int main(void)
{
FILE* fp = NULL; char* filename = "d:\\in.txt";
if ((fp = fopen(filename,"r")) == NULL)
printf("Unable to open file %s\n",filename);
static char ch = '\0';
static char* digits[] = { "zero", "one", "two" ,"three", "four",
"five", "six", "seven", "eight", "nine" };
while ((ch = fgetc(fp)) != EOF)
if (isdigit(ch)) printf("%s",digits[ch - '0']);
else if (ch == '.' ||
ch == '!' || ch == '?') printf("\n");
else printf("%c",ch);
_getch();
return 0;
}Решение задачи: «Переделать код с++ в код с#»
textual
Листинг программы
using System;
using System.Collections.Generic;
using System.IO;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
var path = "d:\\in.txt";
if (!File.Exists(path)) Console.WriteLine($"Unable to open file {path}");
var digits = new List<string> { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };
using (var reader = new StreamReader(path))
{
while (!reader.EndOfStream)
{
var c = (char)reader.Read();
if (char.IsDigit(c)) Console.WriteLine(digits[(int)char.GetNumericValue(c)]);
else if (c == '.' || c == '!' || c == '?') Console.WriteLine();
else Console.Write(c);
}
}
Console.ReadKey(true);
}
}
}