Дана строка, удвоить каждый символ - C#
Формулировка задачи:
Здравствуйте, помогите пожалуйста найти ошибки. Задание :Дана строка, удвоить каждый символ
using System;
namespace Prog1
{
class Program
{
static void Main()
{
int k = 1;
Console.WriteLine("Введите строку :");
string s = Console.ReadLine();
int dlin = s.Length;
for (int i = 0; i < s.Length; i++)
{
while (k <= dlin)
{
s = s.Insert(i+1, s);
k = k + 1;
i = i + 2;
}
}
Console.WriteLine(s);
Console.ReadKey();
}
}
}Решение задачи: «Дана строка, удвоить каждый символ»
textual
Листинг программы
using System;
namespace OtherConsoleExperiments
{
class Program
{
static void Main(string[] args)
{
string source = "Hello From C#";
char[] destChar = new char[source.Length * 2];
int destIndex = 0;
foreach (char c in source)
{
destChar[destIndex++] = c;
destChar[destIndex++] = c;
}
string destString = new string(destChar);
Console.WriteLine(destString);
Console.ReadKey();
}
}
}