Advertisement
dragnscalearmor

C# Day 4 / 100

Feb 17th, 2020
591
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.56 KB | None | 0 0
  1. // The return keyword used in an example, within it's own class with two different methods.
  2.  
  3. using System;
  4.  
  5. namespace Return
  6. {
  7.     public class ReturnString
  8.     {
  9.         public string ReturnFullName(string textOne, string textTwo)
  10.         {
  11.             return textOne + " " + textTwo;
  12.         }
  13.  
  14.         public int ReturnMultiply(int one, int two)
  15.         {
  16.             return one * two;
  17.         }
  18.     }
  19.  
  20.     class Program
  21.     {
  22.         static void Main(string[] args)
  23.         {
  24.             Start();
  25.         }
  26.  
  27.         private static void Start()
  28.         {
  29.             ReturnString returnname = new ReturnString();
  30.  
  31.             Console.WriteLine("First name: (x to exit)");
  32.             string textOne = Console.ReadLine();
  33.  
  34.             if (textOne == "x")
  35.             {
  36.                 Environment.Exit(0);
  37.             }
  38.  
  39.             Console.WriteLine("Last name:");
  40.             string textTwo = Console.ReadLine();
  41.  
  42.             Console.WriteLine("Enter a number:");
  43.             int one = int.Parse(Console.ReadLine());
  44.  
  45.             Console.WriteLine("Enter another number:");
  46.             int two = int.Parse(Console.ReadLine());
  47.  
  48.             Console.WriteLine("Your full name is: " + returnname.ReturnFullName(textOne, textTwo));
  49.             Console.WriteLine(one.ToString("#,##0") + " times " + two.ToString("#,##0") + " = " + returnname.ReturnMultiply(one, two).ToString("#,##0") + "\n\n");
  50.             Console.WriteLine("Press a key...");
  51.             Console.ReadKey();
  52.  
  53.             Console.Clear();
  54.             Start();
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement