50
loading...
This website collects cookies to deliver better user experience
//The following will create our console app in the directory, in the stringFormate.
dotnet new console -o stringFormate
Main
method will be asking for your first and last name, and then it will give you your initials.using System;
namespace string format
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter you first name: ").IsUpper;
string firstName = Console.ReadLine();
Console.WriteLine("Enter you last name: ");
string lastName = Console.ReadLine();
Console.WriteLine($"Your initials are: '{firstName[0]}.{lastName[0]}'");
}
}
}
string interpolation
; this is a way of formatting our output; we can add the $""
to our write lines to call variables from directly in the Console.WriteLine()
method.Console.WriteLine($"Your initials are: '{firstName[0]}.{lastName[0]}'");
[]
. If we take a look at our example, we can see that we already used this to get the first character from our first and the last name gets it our initials.Console.WriteLine($"Your initials are: '{firstName[0]}.{lastName[0]}'");
ToUpper()
method when it's attached to an existing variable. ie fistName.ToUpper()
var == string, double, int, char, bool, long, object
.Console.WriteLine("Enter you first name: ");
string firstName = Console.ReadLine();
var upperFirstName = firstName.ToUpper();
Console.WriteLine("Enter you lastname: ");
string lastName = Console.ReadLine();
var upperLastName = lastName.ToUpper();
Console.WriteLine($"Your initials are: '{upperFirstName[0]}.{upperLastName[0]}'");
real-world
scenarios; this could range from formatting numbers for security reasons or validating that the data that is being used is only received in a specific format itself. .ToLower
the name gives it away if you have made it this far; with this, we can turn all our data into a lower casing format. Explore and see what other methods you can find as well.