{"id":430,"date":"2020-04-26T09:16:56","date_gmt":"2020-04-26T08:16:56","guid":{"rendered":"https:\/\/ibex.tech\/csharp\/?p=430"},"modified":"2022-02-17T06:24:14","modified_gmt":"2022-02-17T06:24:14","slug":"constructors","status":"publish","type":"post","link":"https:\/\/ibex.tech\/csharp\/c-sharp\/classes\/constructors","title":{"rendered":"Constructors"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">Using the same variable names as arguments as the class uses<\/h4>\n\n\n\n<p>Yes you can, like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\tpublic MyClassName (string Category, double Value1, bool Value2)\n\t{\n\t\tthis.Category = Category;\n\t\tthis.Value1 = Value1;\n\t\tthis.Value2 = Value2;\n\t}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Setting values without a constructor<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>\tpublic class MyClassName\n\t{\n\t\tpublic string Category { get; set; }\n\t\tpublic double Value1 { get; set; }\n\t\tpublic bool Value2 { get; set; }\n\t}\n\n\tMyClassName MyClassName1 = new MyClassName() { Category = \"Cat0\", Value1 = 1000, Value2 = true };\n\t<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Using the same variable names as arguments as the class uses Yes you can, like this: Setting values without a constructor<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23],"tags":[],"class_list":["post-430","post","type-post","status-publish","format-standard","hentry","category-classes"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/430","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/comments?post=430"}],"version-history":[{"count":3,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/430\/revisions"}],"predecessor-version":[{"id":434,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/430\/revisions\/434"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/media?parent=430"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/categories?post=430"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/tags?post=430"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}