From the course: C# Essential Training 1: Types and Control Flow
Unlock the full course today
Join today to access over 23,200 courses taught by industry experts.
Cloning and copying objects - C# Tutorial
From the course: C# Essential Training 1: Types and Control Flow
Cloning and copying objects
- Let's look at how these different types work. So reference types or classes, structs, value types, and then the records. Got a method here, just back out of my program.cs, called classes, and I'm going to create an employee, I'm going to initialize it. So I've got a name. Notice the age here, got a birth date back in 1971, means 50 years old with an ID of one, and then here's where we start working with those reference types. So on line 22, I define another variable called other and I set it equal to me. Then I change the first name and the age on the other variable. Now what's going to get written out here on line 27. If I read out me.FirstName and age years old, as well as other first name and age years old. So think about what's the original variable me and what's happened now that I have another reference, this other that points to it. So let's run that quick. Let's see if he got it right. Let's look at the first couple lines here. It says Bizarro Matt is 39, but Bizarro Matt is…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
Understanding classes, structs, and records7m
-
(Locked)
Defining constructors7m 6s
-
(Locked)
Object initialization6m 4s
-
(Locked)
Initialize only properties4m 59s
-
(Locked)
Cloning and copying objects9m 32s
-
(Locked)
Equality comparisons5m 27s
-
(Locked)
Defining abstract classes7m 52s
-
(Locked)
Creating static classes5m 18s
-
(Locked)
Solution: Expressing equality1m 5s
-
-
-
-
-
-