{"id":156,"date":"2009-07-24T12:54:37","date_gmt":"2009-07-24T11:54:37","guid":{"rendered":"http:\/\/www.codingfriends.com\/?p=156"},"modified":"2009-07-24T12:56:32","modified_gmt":"2009-07-24T11:56:32","slug":"local-variables-2","status":"publish","type":"post","link":"https:\/\/www.codingfriends.com\/index.php\/2009\/07\/24\/local-variables-2\/","title":{"rendered":"Local variables"},"content":{"rendered":"<p>This is a tutorial about variable scope, a variable is a means to store data within the context of the program.  For example, if you wish to store a numerical value then you would not store that number in a string, but within a integer or floating point number.  <\/p>\n<p>There are different types of variables, integer \/ string etc, but the scope of a variable is the area in which the variable is defined within block of code that it is situated.<\/p>\n<p>This is some c#  code to demonstrate the difference between local variables and global.<\/p>\n<pre lang=\"csharp\">\r\nclass localvariable\r\n{\r\n       private static int value1 = 1;\r\n       \r\n       private static void global()\r\n       {\r\n              System.Console.WriteLine(\"Global : \" + value1);\r\n       }\r\n       \r\n       public static void Main()\r\n       {\r\n              int value1 = 0;\r\n              System.Console.WriteLine(\"Local : \"  + value1);\r\n              global();\r\n              return;\r\n       }\r\n}\r\n<\/pre>\n<p>save this as localvariable.cs and then compile up the code and run. The output should be.<\/p>\n<pre class=\"consoleoutput\">\r\nLocal : 0\r\nGlobal : 1\r\n<\/pre>\n<p>and as you can tell there are two value1 within the source code whilst one is the global variable and the other is local to the Main method.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is a tutorial about variable scope, a variable is a means to store data within the context of the program. For example, if you wish to store a numerical value then you would not store that number in a string, but within a integer or floating point number. There are different types of variables, &hellip; <a href=\"https:\/\/www.codingfriends.com\/index.php\/2009\/07\/24\/local-variables-2\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Local variables<\/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-156","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\/156","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=156"}],"version-history":[{"count":2,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/156\/revisions"}],"predecessor-version":[{"id":163,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/156\/revisions\/163"}],"wp:attachment":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/media?parent=156"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/categories?post=156"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/tags?post=156"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}