Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

Variables - Changing value at runtime in C#

This example illustrates the behavior of a variable in a program.
The variable is assigned initially and the value is changed in runtime.

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6.  
  7. namespace forgetCode
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13.  
  14. string firstName = "Hi";
  15. string lastName = "Welcomes";
  16.  
  17. Console.WriteLine("Initial Message: " + firstName + " " + lastName);
  18.  
  19. Console.WriteLine("Please enter a name:");
  20. firstName = Console.ReadLine();
  21.  
  22. Console.WriteLine("New Message: " + firstName + " " + lastName);
  23.  
  24. Console.ReadLine();
  25.  
  26.  
  27. }
  28.  
  29.  
  30. }
  31. }


Output:
  1. Initial Message: Hi Welcomes
  2. Please enter a name:
  3. Forget Code
  4. New Message: Forget Code Welcomes


Here the firstName is changed to 'Forget Code' from 'hi'

..