C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,497 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
been trying to make a code to ask my name and put an exact time
This question is related to the following Learning Module
Here's a simple C# program that asks for your name and prints a greeting with the current time:
using System;
class Program
{
static void Main()
{
Console.Write("What's your name? ");
string name = Console.ReadLine();
string time = DateTime.Now.ToString("HH:mm:ss");
Console.WriteLine($"Hello, {name}! The time is {time}.");
}
}
Console.Write
asks for your name.Console.ReadLine()
reads your input.DateTime.Now.ToString("HH:mm:ss")
gets the current time in hours:minutes:seconds format.If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.
hth
Marcin