AnitaN

02.PrimitiveDataTypesVariables/07.StringsAndObjects

Mar 9th, 2014
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.70 KB | None | 0 0
  1. //Problem 7.Strings and Objects
  2. //Declare two string variables and assign them with β€œHello” and β€œWorld”. Declare an object variable and assign it with the concatenation of the first two variables (mind adding an interval between). Declare a third string variable and initialize it with the value of the object variable (you should perform type casting).
  3.  
  4. using System;
  5.  
  6. class StringsAndObjects
  7. {
  8.     static void Main()
  9.     {
  10.         string firstString = "Hello";
  11.         string secondString = "World";
  12.         object greeting = firstString + " " + secondString;
  13.         //Casting from object to string
  14.         string thirdString = (string)greeting;
  15.         Console.WriteLine(thirdString);
  16.     }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment