Write a C# Sharp program to create a new string using first two characters of a given string. If the string length is less than 2 then return the original string
- برمجة سي شارب
- برمجة
- 2021-05-16
- MarwaMohammed
الأجوبة
using System;
namespace exercises
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(test("Hello"));
Console.WriteLine(test("Hi"));
Console.WriteLine(test("H"));
Console.WriteLine(test(" "));
Console.ReadLine();
}
public static string test(string s1)
{
return s1.Length < 2 ? s1 : s1.Substring(0, 2);
}
}
}أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال
