Write a C# Sharp program to create a new string of length 2, using first two characters of a given string. If the given string length is less than 2 use '#' as missing characters
- برمجة سي شارب
- برمجة
- 2021-05-17
- MarwaMohammed
الأجوبة
using System;
namespace exercises
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(test("Hello"));
Console.WriteLine(test("Python"));
Console.WriteLine(test("a"));
Console.WriteLine(test(""));
Console.ReadLine();
}
public static string test(string s1)
{
if (s1.Length >= 2)
{
s1 = s1.Substring(0, 2);
}
else if (s1.Length > 0)
{
s1 = s1.Substring(0, 1) + "#";
}
else
{
s1 = "##";
}
return s1;
}
}
}
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال