{"id":516,"date":"2010-01-14T23:02:36","date_gmt":"2010-01-14T23:02:36","guid":{"rendered":"http:\/\/www.codingfriends.com\/?p=516"},"modified":"2010-01-14T23:03:13","modified_gmt":"2010-01-14T23:03:13","slug":"overloading-methods-c","status":"publish","type":"post","link":"https:\/\/www.codingfriends.com\/index.php\/2010\/01\/14\/overloading-methods-c\/","title":{"rendered":"Overloading methods &#8211; c#"},"content":{"rendered":"<p>Overloading a method in a class is making a method name be able to take different parameters and return values.  A good example would be if you had a method that was adding a passed value to a internal private variable, but wanted to be able to do different processes if the value is a integer \/double  \/ floating point number.  To overload a method as above the code would be similar to this<\/p>\n<pre lang=\"csharp\">\r\npublic void addNumber(int intValue)\r\n{\r\n....\r\n}\r\n\r\npublic void addNumber(double doubleValue)\r\n{\r\n...\r\n}\r\n<\/pre>\n<p>Here is a basic overloading method, to just print out to the console a message.<\/p>\n<pre lang=\"csharp\">\r\nusing System;\r\n\r\nnamespace inheritance\r\n{\r\n\t\r\n\tclass firstClass\r\n\t{\r\n\t\tpublic void printClassName()\r\n\t\t{\r\n\t\t\tConsole.WriteLine(\"FirstClass\");\r\n\t\t}\r\n\t\t\r\n\t\t\/\/ overloading the method printClassName\r\n\t\tpublic void printClassName(String additionalMessage)\r\n\t\t{\r\n\t\t\tConsole.WriteLine(\"FirstClass  : \" + additionalMessage);\r\n\t\t}\r\n\t}\r\n\t\r\n\tclass MainClass\r\n\t{\r\n\t\tpublic static void Main(string[] args)\r\n\t\t{\r\n\t\t\tfirstClass first = new firstClass();\r\n\t\t\tfirst.printClassName();\r\n\t\t\t\/\/ call the overloaded function to pass in a message to print out.\r\n\t\t\tfirst.printClassName(\"overloaded\");\r\n\t\t}\r\n\t}\r\n}\r\n<\/pre>\n<p>output would be <\/p>\n<pre lang=\"bash\">\r\nFirstClass\r\nFirstClass  : overloaded\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Overloading a method in a class is making a method name be able to take different parameters and return values. A good example would be if you had a method that was adding a passed value to a internal private variable, but wanted to be able to do different processes if the value is a &hellip; <a href=\"https:\/\/www.codingfriends.com\/index.php\/2010\/01\/14\/overloading-methods-c\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Overloading methods &#8211; c#<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[58],"class_list":["post-516","post","type-post","status-publish","format-standard","hentry","category-c_sharp","tag-overloading"],"_links":{"self":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/516","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/comments?post=516"}],"version-history":[{"count":2,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/516\/revisions"}],"predecessor-version":[{"id":518,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/516\/revisions\/518"}],"wp:attachment":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/media?parent=516"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/categories?post=516"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/tags?post=516"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}