Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApp1
- {
- class Program
- {
- static void Main(string[] args)
- {
- string name; //Declaring variable "name" of string type
- name = ""; //Initializing variable "name" to null
- Console.WriteLine("Enter your full name plz."); //Print instruction for user to assign value to "name"
- name = Console.ReadLine(); //Actually assign user input to "name"
- DisplayFullName(name); //Call DisplayFullName method sending value of "name"
- Console.ReadKey(); //Halts the program until user inputs a key
- }
- public static string GetFirstName (string name) //Method called in DisplayFullName
- {
- int space; //Declaring variable "space" of integer type
- space = 0; //Initializing variable "space" to null
- space = name.IndexOf(" "); //Assigning index of space character in string "name" to integer "space"
- string fName; //Declaring variable "fName" of string type
- fName = ""; //Initializing variable "fName" to null
- fName = name.Substring(0, space); //Assigning value of "fName" to value of "name" from index of 0 to index represented by integer variable "space"
- return fName; //Returning value of "fName"
- }
- public static string GetLastName(string name) //Method called in DisplayFullName
- {
- int space; //Declaring variable "space" of integer type
- space = 0; //Initializing variable "space" to null
- space = name.IndexOf(" "); //Assigning index of space character in string "name" to integer "space"
- string lName; //Declaring variable "lName" of string type
- lName = ""; //Initializing variable "lName" to null
- lName = name.Substring(space + 1); //Assigning value of "lName" to value of "name" from index of 0 to index represented by integer variable "space" plus one to avoid including the space itself in "lName"
- return lName; //Returning value of "lName"
- }
- public static void DisplayFullName (string name) //Method called in Main
- {
- Console.WriteLine("Your first name is {0} and your last name is {1}.",GetFirstName(name), GetLastName(name)); //Call necessary methods and output information to console
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement