Hi Guys
NP57 Meaning of the code
I got this program from the following website. I have problem in understanding the program.
What do the above codes mean and what is the purpose of the above code. Because without these two codes program is producing same output. Anyone knows please explain the reason.
http://www.c-sharpcorner.com/UploadFile/rmcochran/chsarp_memory401152006094206AM/chsarp_memory4.aspx
Thank you
using System;
class Program_byMaha
{
public static void Main()
Shoe pgm = new Shoe();
Dude Bill = new Dude();
Bill.Name = "Bill";
//Bill.LeftShoe = new Shoe();
//Bill.RightShoe = new Shoe();
Bill.LeftShoe.Color = Bill.RightShoe.Color = "Blue";
Dude Ted = Bill.CopyDude();
Ted.Name = "Ted";
Ted.LeftShoe.Color = Ted.RightShoe.Color = "Red";
Console.WriteLine(Bill.ToString());
Console.WriteLine(Ted.ToString());
}
public struct Shoe
public string Color;
public class Dude
public string Name;
public Shoe RightShoe;
public Shoe LeftShoe;
public Dude CopyDude()
Dude newPerson = new Dude();
newPerson.Name = Name;
newPerson.LeftShoe = LeftShoe;
newPerson.RightShoe = RightShoe;
return newPerson;
public override string ToString()
return (Name + " : Dude!, I have a " + RightShoe.Color
+ " shoe on my right foot, and a " + LeftShoe.Color + " on my left foot.");
/*
Bill : Dude!, I have a Blue shoe on my right foot, and a Blue on my left foot.
Ted : Dude!, I have a Red shoe on my right foot, and a Red on my left foot.
*/