Advertisement
tvarbanov

CSharp2-03-01

Jan 3rd, 2014
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.69 KB | None | 0 0
  1. using System;
  2.  
  3. namespace HelloMethodName
  4. {
  5.     public class HelloMethod
  6.     {
  7.         //Write a method that asks the user for his name and prints “Hello, <name>” (for example, “Hello, Peter!”). Write a program to test this method.
  8.  
  9.         public static string Hello(string name)
  10.         {
  11.             string greeting = "Hello, " + name + "!";
  12.             return greeting;
  13.         }
  14.  
  15.         static void Main()
  16.         {
  17.             //Get the name
  18.             Console.Write("What's your name : ");
  19.             string myName = Console.ReadLine();
  20.  
  21.             Console.WriteLine(Hello(myName)); //Sends the variable to the method and prints the result
  22.  
  23.         }
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement