{"id":168,"date":"2009-07-24T22:16:08","date_gmt":"2009-07-24T21:16:08","guid":{"rendered":"http:\/\/www.codingfriends.com\/?p=168"},"modified":"2009-07-24T22:16:08","modified_gmt":"2009-07-24T21:16:08","slug":"method-add-two-numbers","status":"publish","type":"post","link":"https:\/\/www.codingfriends.com\/index.php\/2009\/07\/24\/method-add-two-numbers\/","title":{"rendered":"Method &#8211; Add Two numbers"},"content":{"rendered":"<p>This tutorial uses the same code as <a href=\"http:\/\/www.codingfriends.com\/index.php\/2009\/07\/24\/add-two-numbers\/\"  target=\"_blank\">Add two numbers<\/a> but includes a function\/method to add two numbers together and return a value.  In this case the value is a integer (int) and that is why the int is just before the name of the method (addIntegers) with two parameters passed to the method, these are the values that are being added together.  I have called them a and b, so that they are different names to the variables within the main method.<\/p>\n<p>The source code<\/p>\n<pre lang=\"csharp\">\r\nusing System;       \/\/ for the console object\r\n\r\nclass addtwonumbers\r\n{\r\n       public static int addIntegers(int a, int b)\r\n       {\r\n              return (a + b);\r\n       }\r\n       \r\n       public static void Main()\r\n       {\r\n              try \r\n              {\r\n                     \/\/ output to the console\r\n                     Console.Write(\"Please enter value 1 : \");\r\n                     \/\/ readin the console input, and then convert to a integer value\r\n                     int val1 = Convert.ToInt32(Console.ReadLine());\r\n                     Console.Write(\"Please enter value 2 : \");\r\n                     int val2 = Convert.ToInt32(Console.ReadLine());\r\n                     \/\/ write out the answer \r\n                     Console.WriteLine(\"Answer = \" + addIntegers(val1,val2));\r\n              }\r\n              catch (Exception e)\r\n              {\r\n                     \/\/ any errors. Like converting a string to a integer value\r\n                     Console.WriteLine(\"Error : \" + e.ToString());\r\n              }\r\n       }\r\n}\r\n<\/pre>\n<p>save as addtwonumbers_function.cs, this program will function the same as the previous tutorial apart from the inner working will call the method.  The method programming allows for one method to be called multiple times, e.g. Within the example above there could be a method that was 5 lines in length and instead of writing the same 5 lines each time, you just write a method that is called.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial uses the same code as Add two numbers but includes a function\/method to add two numbers together and return a value. In this case the value is a integer (int) and that is why the int is just before the name of the method (addIntegers) with two parameters passed to the method, these &hellip; <a href=\"https:\/\/www.codingfriends.com\/index.php\/2009\/07\/24\/method-add-two-numbers\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Method &#8211; Add Two numbers<\/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":[14,398,13,400],"class_list":["post-168","post","type-post","status-publish","format-standard","hentry","category-c_sharp","tag-c-sharp","tag-linux","tag-mono","tag-windows"],"_links":{"self":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/168","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=168"}],"version-history":[{"count":1,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/168\/revisions"}],"predecessor-version":[{"id":169,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/168\/revisions\/169"}],"wp:attachment":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/media?parent=168"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/categories?post=168"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/tags?post=168"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}