Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
      You have completed C# Objects!
      
    
You have completed C# Objects!
Preview
    
      
  Multiple methods in the same class can have the same name. They're called overloaded methods.
This video doesn't have any notes.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
                      In C#, a class can have multiple
methods with the same name.
                      0:00
                    
                    
                      For example, there are 18 methods in
the console class all named write.
                      0:03
                    
                    
                      They all take different types and
numbers of arguments.
                      0:08
                    
                    
                      This is useful because not all data that a
method can handle comes in the same type.
                      0:11
                    
                    
                      The DistanceTo method right now calculates
the distance between a point and
                      0:18
                    
                    
                      the x and y values parsed in.
                      0:22
                    
                    
                      We could also have
a DistanceTo method that
                      0:24
                    
                    
                      calculates the distance
between two-point objects.
                      0:28
                    
                    
                      This method can just call the other
DistanceTo method like this.
                      0:34
                    
                    
                      What we've just done is
overloaded the DistanceTo method.
                      0:48
                    
                    
                      To overload a method means to have two
methods with the same name that take
                      0:51
                    
                    
                      different parameters.
                      0:56
                    
                    
                      As you can see,
methods are the moving parts of an object.
                      0:57
                    
                    
                      It's where the code that does stuff lives.
                      1:01
                    
                    
                      Fields in a class
are the substance of the object.
                      1:04
                    
                    
                      They're what make two objects
of the same type unique.
                      1:08
                    
                    
                      They contain the object's data.
                      1:12
                    
                    
                      You may have also noticed that methods
all use the fields in some way.
                      1:15
                    
                    
                      This is something you'll
see throughout this course.
                      1:20
                    
                    
                      One of the purposes of objects
is to combine data and
                      1:23
                    
                    
                      the methods that are closely tied to
the data together in one elegant package.
                      1:27
                    
                    
                      Now that we've learned how to model
an object using attributes and behaviors,
                      1:32
                    
                    
                      we can go on to learn some of the core
principles of object-oriented programming.
                      1:37
                    
                    
                      This is where it gets really interesting.
                      1:41
                    
              
        You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up