{"id":375,"date":"2020-07-15T06:25:30","date_gmt":"2020-07-15T06:25:30","guid":{"rendered":"http:\/\/certcent.io\/?p=375"},"modified":"2020-07-15T06:25:30","modified_gmt":"2020-07-15T06:25:30","slug":"learning-classes-with-powershell-5-0","status":"publish","type":"post","link":"https:\/\/certcent.io\/index.php\/2020\/07\/15\/learning-classes-with-powershell-5-0\/","title":{"rendered":"Learning constructors using classes in Powershell 5.0"},"content":{"rendered":"<p>Classes are at the core of C++ programming language, but it takes time to compile and debug using C++.  If you want to learn about the very basics of classes, I suggest you give Powershell a try.<br \/>\nThis sample will cover inheritance, classes, and instantiation.<br \/>\nCreating a simple class:<\/p>\n<pre class=\"lang:default decode:true \" title=\"Creating a simple class\">class Computers { [string]$brand; [int]$year; Computers() { write-host -object \"Called without any parameters\" } Computers ([string]$brand,[int]$year) { $this.brand = $brand; $this.year = $year }  }<\/pre>\n<p>Instantiation of your new class:<\/p>\n<pre class=\"lang:default decode:true \">$myNew = [Computers]::new()\n$myNew2 = [Computers]::new(\"Asus\",2020)<\/pre>\n<p>Inheritance of your new class:<\/p>\n<pre class=\"lang:default decode:true \">class IT : Computers { Hardware() { } }<\/pre>\n<p>&nbsp;<br \/>\n&nbsp;<br \/>\n<!--EndFragment --><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Classes are at the core of C++ programming language, but it takes time to compile and debug using C++. If you want to learn about the very basics of classes, I suggest you give Powershell a try. This sample will cover inheritance, classes, and instantiation. Creating a simple class: class Computers { [string]$brand; [int]$year; Computers()&hellip; <a class=\"more-link\" href=\"https:\/\/certcent.io\/index.php\/2020\/07\/15\/learning-classes-with-powershell-5-0\/\">Continue reading <span class=\"screen-reader-text\">Learning constructors using classes in Powershell 5.0<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/certcent.io\/index.php\/wp-json\/wp\/v2\/posts\/375"}],"collection":[{"href":"https:\/\/certcent.io\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/certcent.io\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/certcent.io\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/certcent.io\/index.php\/wp-json\/wp\/v2\/comments?post=375"}],"version-history":[{"count":0,"href":"https:\/\/certcent.io\/index.php\/wp-json\/wp\/v2\/posts\/375\/revisions"}],"wp:attachment":[{"href":"https:\/\/certcent.io\/index.php\/wp-json\/wp\/v2\/media?parent=375"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/certcent.io\/index.php\/wp-json\/wp\/v2\/categories?post=375"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/certcent.io\/index.php\/wp-json\/wp\/v2\/tags?post=375"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}