{"action":"created","comment":{"url":"https://api.github.com/repos/dotnet/docs/pulls/comments/144915949","pull_request_review_id":69633337,"id":144915949,"diff_hunk":"@@ -0,0 +1,177 @@\n+---\n+title: Quick Starts - Introduction to Classes - C# Guide\n+description: Create your first C# program and explore object oriented concepts\n+keywords: C#, Get Started, Lessons, Classes, Object Oriented Programming\n+author: billwagner\n+ms.author: wiwagn\n+ms.date: 10/11/2017\n+ms.topic: article\n+ms.prod: .net\n+ms.technology: devlang-csharp\n+ms.devlang: csharp\n+---\n+# Introduction to classes\n+\n+This lesson assumes installed [.NET Core](http://dot.net/core) and [Visual Studio Code](https://code.visualstudio.com/), or [Visual Studio](https://www.visualstudio.com/) on Mac or Windows.\n+\n+## Create your application\n+\n+Create a directory named **classes**. You'll build your application there. Change to that directory and type `dotnet new console`. This command creates your application. Open **Program.cs**. It should look like this:\n+\n+```csharp\n+using System;\n+\n+namespace classes\n+{\n+    class Program\n+    {\n+        static void Main(string[] args)\n+        {\n+            Console.WriteLine(\"Hello World!\");\n+        }\n+    }\n+}\n+```\n+\n+In this quick start, you're going to create new types that represent a bank account. Typically developers define each class in a different text file. That makes it easier to manage as a program grows in size.  Create a new file named **BankAccount.cs** in the **classes** directory. \n+\n+This file will contain the deefinition of a ***bank account***. Object Oriented programming organizes code by creating types in the form of ***classes***. These classes contain the code that represent a concept. The `BankAccount` class represents the responsibilities and properties of a bank account. In this quick start, the bank account supports this behavior:\n+\n+1. It has a 10-digit number that uniquely identifies the bank account.\n+1. It has a string that stores the name or names of the owners.\n+1. The balance can be retrieved.\n+1. It accepts deposits.\n+1. It accepts withdrawals.\n+\n+## Define the bank account type\n+\n+You can start by creating the basics of a class that defines that behavior. It would look like this:\n+\n+```csharp\n+using System;\n+\n+namespace classes\n+{\n+    public class BankAccount\n+    {\n+        public string Number { get; }\n+        public string Owner { get; set; }\n+        public decimal Balance { get; }\n+\n+        public void MakeDeposit(decimal amount, DateTime date, string note)\n+        {\n+        }\n+\n+        public void MakeWithdrawal(decimal amount, DateTime date, string payee, string note)\n+        {\n+        }\n+    }\n+}\n+```\n+\n+Before going on, let's take a look at what you've built.  The `namespace` declaration provides a way to logically organize your code. This quick start is relatively small, so you'll put all the code in one namespace. \n+\n+The `public class BankAccount` defines the class, or type, you are creating. Everything inside the `{` and `}` that follows the class declaration defines the behavior of the class. There are five ***members*** of the `BankAccount` class. The first three are ***properties***. Properties are data elements, but can have code that enforces validation or other rules. The last two are ***methods***. Methods are blocks of code that peform a single function. Reading the names of each of the members should provide enough information for you or another developer to understand what the class does.\n+\n+## Open a new account\n+\n+The first feature to implement is to open a bank account. When a customer opens an account, they must supply an initial balance, and information about the owner or owners of that account. \n+\n+Creating a new object of the `BankAccount` type means defining a ***constructor*** that assigns those values. A ***constructor*** is a member that has the same name as the class. It is used to initialize objects of that class type. Add the following constructor to the `BankAccount` type:\n+\n+```csharp\n+public BankAccount(string name, decimal initialBalance)\n+{\n+    this.Owner = name;\n+    this.Balance = initialBalance;\n+}\n+```\n+\n+Constructors are called when you create an object using `new`. Replace the line `Console.WriteLine(\"Hello World!\");` in ***program.cs*** with the following line (replace `<name>` with your name):\n+\n+```csharp\n+var account = new BankAccount(\"<name\", 1000);\n+Console.WriteLine($\"Account {account.Number} was created for {account.Owner} with {account.Balance} initial balance\".);\n+```\n+\n+Type `dotnet run` to see what happens.  \n+\n+Did you notice that the account number is blank? It's time to fix that. The account number should be assigned when the object is constructed. But, it shouldn't be the responsibility of the caller to create that. The `BankAccount` class code should know how to assign new account numbers.  A simple way to do this is to start with a 10-digit number. Increment it when each new account is created. Finally, store the current account number when an object is constructed.\n+\n+Add the following member declaration to the `BankAccount` class:\n+\n+```csharp\n+private static int accountNumberSeed = 1234567890;\n+```\n+\n+This is data member. It's `private`, which means it can only be accessed by code inside the `BankAccount` class. It's a way of separating the public responsibilities (like having an account number) from the private implementation (how account numbers are generated.) Add the following two lines to the constructor to assign the account number:\n+\n+```csharp\n+this.Number = accountNumberSeed.ToString();\n+accountNumberSeed++;\n+```\n+\n+Type `dotnet run` to see the results.\n+\n+## Create deposits and withdrawals\n+\n+Your bank account class needs to accept deposits and withdrawals to work correctly. Let's implement deposits and withdrawals by creating a journal of every transaction for the account. That has a few advantages or simply updating the balance on each transaction. The history can be used to audit all transactions and manage daily balances. \n+\n+Let's start by creating a new type to represent a transaction. This is a simple type that doesn't have any responsibilities. It needs a few properties. Create a new file named ***Transaction.cs***. Add the following code to it:\n+\n+[!code-csharp[Transaction](../../../samples/csharp/classes-quickstart/Transaction.cs \"Transaction declaration\")]\n+\n+Now, let's add a <xref:System.Collections.Generic.List%601> of `Transaction` objects to the `BankAccount` class. Add the following declaration:\n+\n+[!code-csharp[TransactionDecl](../../../samples/csharp/classes-quickstart/BankAccount.cs#TransactionDeclaration \"Transaction declaration\")]\n+\n+The <xref:System.Collections.Generic.List%601> class requires you to import a different namespace. Add the following at the beginning of **BankAccount.cs**:\n+\n+```csharp\n+using System.Collections.Generic;\n+```\n+\n+Now, let's change how the `Balance` is reported.  It can be found by summing the values of all transactions. Modify the declaration of `Balance` in the `BankAccount` class to the following:\n+\n+[!code-csharp[BalanceComputation](../../../samples/csharp/classes-quickstart/BankAccount.cs#BalanceComputation \"Computing the balance\")]\n+\n+This example shows an important aspect of ***properties***. You're now computing the balance when another programmer asks for the value. Your computation enumerates all transactions, and provides the sum as the current balance.\n+\n+Next implement the `MakeDeposit` and `MakeWithdrawal` methods:\n+\n+[!code-csharp[DepositAndWithdrawal](../../../samples/csharp/classes-quickstart/BankAccount.cs#DepositAndWithdrawal \"Make deposits and withdrawals\")]\n+\n+The constructor should get one change so that it adds an initial transaction, rather than updating the balance directly. Since you already wrote the `MakeDeposit` method, call it from your constructor. The finished constructor should look like this:\n+\n+[!code-csharp[Constructor](../../../samples/csharp/classes-quickstart/BankAccount.cs#Constructor \"The final version of the constructor\")]\n+\n+The <xref:System.DateTime.Now> is a property that returns the current date and time. Test this by adding a few deposits and withdrawals in your `Main` method:","path":"docs/csharp/quick-starts/introduction-to-classes.md","position":148,"original_position":148,"commit_id":"8a9f4de9d54a7c037e3b137ab5c9002ae02c3255","original_commit_id":"8a9f4de9d54a7c037e3b137ab5c9002ae02c3255","user":{"login":"rpetrusha","id":10886961,"avatar_url":"https://avatars2.githubusercontent.com/u/10886961?v=4","gravatar_id":"","url":"https://api.github.com/users/rpetrusha","html_url":"https://github.com/rpetrusha","followers_url":"https://api.github.com/users/rpetrusha/followers","following_url":"https://api.github.com/users/rpetrusha/following{/other_user}","gists_url":"https://api.github.com/users/rpetrusha/gists{/gist_id}","starred_url":"https://api.github.com/users/rpetrusha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rpetrusha/subscriptions","organizations_url":"https://api.github.com/users/rpetrusha/orgs","repos_url":"https://api.github.com/users/rpetrusha/repos","events_url":"https://api.github.com/users/rpetrusha/events{/privacy}","received_events_url":"https://api.github.com/users/rpetrusha/received_events","type":"User","site_admin":false},"body":"Delete \"The\"\r\nAdd displayProperty=nameWithType\r\n","created_at":"2017-10-16T17:39:14Z","updated_at":"2017-10-16T17:45:47Z","html_url":"https://github.com/dotnet/docs/pull/3403#discussion_r144915949","pull_request_url":"https://api.github.com/repos/dotnet/docs/pulls/3403","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/dotnet/docs/pulls/comments/144915949"},"html":{"href":"https://github.com/dotnet/docs/pull/3403#discussion_r144915949"},"pull_request":{"href":"https://api.github.com/repos/dotnet/docs/pulls/3403"}}},"pull_request":{"url":"https://api.github.com/repos/dotnet/docs/pulls/3403","id":146561074,"html_url":"https://github.com/dotnet/docs/pull/3403","diff_url":"https://github.com/dotnet/docs/pull/3403.diff","patch_url":"https://github.com/dotnet/docs/pull/3403.patch","issue_url":"https://api.github.com/repos/dotnet/docs/issues/3403","number":3403,"state":"open","locked":false,"title":"Create classes QuickStart","user":{"login":"BillWagner","id":493969,"avatar_url":"https://avatars2.githubusercontent.com/u/493969?v=4","gravatar_id":"","url":"https://api.github.com/users/BillWagner","html_url":"https://github.com/BillWagner","followers_url":"https://api.github.com/users/BillWagner/followers","following_url":"https://api.github.com/users/BillWagner/following{/other_user}","gists_url":"https://api.github.com/users/BillWagner/gists{/gist_id}","starred_url":"https://api.github.com/users/BillWagner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BillWagner/subscriptions","organizations_url":"https://api.github.com/users/BillWagner/orgs","repos_url":"https://api.github.com/users/BillWagner/repos","events_url":"https://api.github.com/users/BillWagner/events{/privacy}","received_events_url":"https://api.github.com/users/BillWagner/received_events","type":"User","site_admin":false},"body":"First draft, and first set of code samples.\r\n\r\nThis will be the final quick start, once readers have installed their own development environment and installed the .NET Core SDK.\r\n\r\nFixes #3280 \r\n\r\n/cc @rowanmiller @LadyNaggaga @shanselman \r\n\r\n[Internal review link](https://review.docs.microsoft.com/en-us/dotnet/csharp/quick-starts/introduction-to-classes?branch=pr-en-us-3403)","created_at":"2017-10-13T21:46:15Z","updated_at":"2017-10-16T17:45:47Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1759f62d308646b26c4e5605a440ecc5ef8d6dfb","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/dotnet/docs/pulls/3403/commits","review_comments_url":"https://api.github.com/repos/dotnet/docs/pulls/3403/comments","review_comment_url":"https://api.github.com/repos/dotnet/docs/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dotnet/docs/issues/3403/comments","statuses_url":"https://api.github.com/repos/dotnet/docs/statuses/8a9f4de9d54a7c037e3b137ab5c9002ae02c3255","head":{"label":"BillWagner:setup-local-environment-quickstart","ref":"setup-local-environment-quickstart","sha":"8a9f4de9d54a7c037e3b137ab5c9002ae02c3255","user":{"login":"BillWagner","id":493969,"avatar_url":"https://avatars2.githubusercontent.com/u/493969?v=4","gravatar_id":"","url":"https://api.github.com/users/BillWagner","html_url":"https://github.com/BillWagner","followers_url":"https://api.github.com/users/BillWagner/followers","following_url":"https://api.github.com/users/BillWagner/following{/other_user}","gists_url":"https://api.github.com/users/BillWagner/gists{/gist_id}","starred_url":"https://api.github.com/users/BillWagner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BillWagner/subscriptions","organizations_url":"https://api.github.com/users/BillWagner/orgs","repos_url":"https://api.github.com/users/BillWagner/repos","events_url":"https://api.github.com/users/BillWagner/events{/privacy}","received_events_url":"https://api.github.com/users/BillWagner/received_events","type":"User","site_admin":false},"repo":{"id":45638874,"name":"docs","full_name":"BillWagner/docs","owner":{"login":"BillWagner","id":493969,"avatar_url":"https://avatars2.githubusercontent.com/u/493969?v=4","gravatar_id":"","url":"https://api.github.com/users/BillWagner","html_url":"https://github.com/BillWagner","followers_url":"https://api.github.com/users/BillWagner/followers","following_url":"https://api.github.com/users/BillWagner/following{/other_user}","gists_url":"https://api.github.com/users/BillWagner/gists{/gist_id}","starred_url":"https://api.github.com/users/BillWagner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BillWagner/subscriptions","organizations_url":"https://api.github.com/users/BillWagner/orgs","repos_url":"https://api.github.com/users/BillWagner/repos","events_url":"https://api.github.com/users/BillWagner/events{/privacy}","received_events_url":"https://api.github.com/users/BillWagner/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/BillWagner/docs","description":".NET Core documentation (work in progress).","fork":true,"url":"https://api.github.com/repos/BillWagner/docs","forks_url":"https://api.github.com/repos/BillWagner/docs/forks","keys_url":"https://api.github.com/repos/BillWagner/docs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/BillWagner/docs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/BillWagner/docs/teams","hooks_url":"https://api.github.com/repos/BillWagner/docs/hooks","issue_events_url":"https://api.github.com/repos/BillWagner/docs/issues/events{/number}","events_url":"https://api.github.com/repos/BillWagner/docs/events","assignees_url":"https://api.github.com/repos/BillWagner/docs/assignees{/user}","branches_url":"https://api.github.com/repos/BillWagner/docs/branches{/branch}","tags_url":"https://api.github.com/repos/BillWagner/docs/tags","blobs_url":"https://api.github.com/repos/BillWagner/docs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/BillWagner/docs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/BillWagner/docs/git/refs{/sha}","trees_url":"https://api.github.com/repos/BillWagner/docs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/BillWagner/docs/statuses/{sha}","languages_url":"https://api.github.com/repos/BillWagner/docs/languages","stargazers_url":"https://api.github.com/repos/BillWagner/docs/stargazers","contributors_url":"https://api.github.com/repos/BillWagner/docs/contributors","subscribers_url":"https://api.github.com/repos/BillWagner/docs/subscribers","subscription_url":"https://api.github.com/repos/BillWagner/docs/subscription","commits_url":"https://api.github.com/repos/BillWagner/docs/commits{/sha}","git_commits_url":"https://api.github.com/repos/BillWagner/docs/git/commits{/sha}","comments_url":"https://api.github.com/repos/BillWagner/docs/comments{/number}","issue_comment_url":"https://api.github.com/repos/BillWagner/docs/issues/comments{/number}","contents_url":"https://api.github.com/repos/BillWagner/docs/contents/{+path}","compare_url":"https://api.github.com/repos/BillWagner/docs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/BillWagner/docs/merges","archive_url":"https://api.github.com/repos/BillWagner/docs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/BillWagner/docs/downloads","issues_url":"https://api.github.com/repos/BillWagner/docs/issues{/number}","pulls_url":"https://api.github.com/repos/BillWagner/docs/pulls{/number}","milestones_url":"https://api.github.com/repos/BillWagner/docs/milestones{/number}","notifications_url":"https://api.github.com/repos/BillWagner/docs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/BillWagner/docs/labels{/name}","releases_url":"https://api.github.com/repos/BillWagner/docs/releases{/id}","deployments_url":"https://api.github.com/repos/BillWagner/docs/deployments","created_at":"2015-11-05T20:57:32Z","updated_at":"2017-04-09T01:27:07Z","pushed_at":"2017-10-16T15:16:59Z","git_url":"git://github.com/BillWagner/docs.git","ssh_url":"git@github.com:BillWagner/docs.git","clone_url":"https://github.com/BillWagner/docs.git","svn_url":"https://github.com/BillWagner/docs","homepage":"http://dotnet.readthedocs.org","size":347970,"stargazers_count":1,"watchers_count":1,"language":null,"has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4,"mirror_url":null,"open_issues_count":0,"forks":4,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"dotnet:master","ref":"master","sha":"a5554380bd0cccdad0b7b5a2a60ac14e9988f11f","user":{"login":"dotnet","id":9141961,"avatar_url":"https://avatars0.githubusercontent.com/u/9141961?v=4","gravatar_id":"","url":"https://api.github.com/users/dotnet","html_url":"https://github.com/dotnet","followers_url":"https://api.github.com/users/dotnet/followers","following_url":"https://api.github.com/users/dotnet/following{/other_user}","gists_url":"https://api.github.com/users/dotnet/gists{/gist_id}","starred_url":"https://api.github.com/users/dotnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dotnet/subscriptions","organizations_url":"https://api.github.com/users/dotnet/orgs","repos_url":"https://api.github.com/users/dotnet/repos","events_url":"https://api.github.com/users/dotnet/events{/privacy}","received_events_url":"https://api.github.com/users/dotnet/received_events","type":"Organization","site_admin":false},"repo":{"id":35890081,"name":"docs","full_name":"dotnet/docs","owner":{"login":"dotnet","id":9141961,"avatar_url":"https://avatars0.githubusercontent.com/u/9141961?v=4","gravatar_id":"","url":"https://api.github.com/users/dotnet","html_url":"https://github.com/dotnet","followers_url":"https://api.github.com/users/dotnet/followers","following_url":"https://api.github.com/users/dotnet/following{/other_user}","gists_url":"https://api.github.com/users/dotnet/gists{/gist_id}","starred_url":"https://api.github.com/users/dotnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dotnet/subscriptions","organizations_url":"https://api.github.com/users/dotnet/orgs","repos_url":"https://api.github.com/users/dotnet/repos","events_url":"https://api.github.com/users/dotnet/events{/privacy}","received_events_url":"https://api.github.com/users/dotnet/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dotnet/docs","description":"This repository contains .NET Documentation.","fork":false,"url":"https://api.github.com/repos/dotnet/docs","forks_url":"https://api.github.com/repos/dotnet/docs/forks","keys_url":"https://api.github.com/repos/dotnet/docs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dotnet/docs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dotnet/docs/teams","hooks_url":"https://api.github.com/repos/dotnet/docs/hooks","issue_events_url":"https://api.github.com/repos/dotnet/docs/issues/events{/number}","events_url":"https://api.github.com/repos/dotnet/docs/events","assignees_url":"https://api.github.com/repos/dotnet/docs/assignees{/user}","branches_url":"https://api.github.com/repos/dotnet/docs/branches{/branch}","tags_url":"https://api.github.com/repos/dotnet/docs/tags","blobs_url":"https://api.github.com/repos/dotnet/docs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dotnet/docs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dotnet/docs/git/refs{/sha}","trees_url":"https://api.github.com/repos/dotnet/docs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dotnet/docs/statuses/{sha}","languages_url":"https://api.github.com/repos/dotnet/docs/languages","stargazers_url":"https://api.github.com/repos/dotnet/docs/stargazers","contributors_url":"https://api.github.com/repos/dotnet/docs/contributors","subscribers_url":"https://api.github.com/repos/dotnet/docs/subscribers","subscription_url":"https://api.github.com/repos/dotnet/docs/subscription","commits_url":"https://api.github.com/repos/dotnet/docs/commits{/sha}","git_commits_url":"https://api.github.com/repos/dotnet/docs/git/commits{/sha}","comments_url":"https://api.github.com/repos/dotnet/docs/comments{/number}","issue_comment_url":"https://api.github.com/repos/dotnet/docs/issues/comments{/number}","contents_url":"https://api.github.com/repos/dotnet/docs/contents/{+path}","compare_url":"https://api.github.com/repos/dotnet/docs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dotnet/docs/merges","archive_url":"https://api.github.com/repos/dotnet/docs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dotnet/docs/downloads","issues_url":"https://api.github.com/repos/dotnet/docs/issues{/number}","pulls_url":"https://api.github.com/repos/dotnet/docs/pulls{/number}","milestones_url":"https://api.github.com/repos/dotnet/docs/milestones{/number}","notifications_url":"https://api.github.com/repos/dotnet/docs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dotnet/docs/labels{/name}","releases_url":"https://api.github.com/repos/dotnet/docs/releases{/id}","deployments_url":"https://api.github.com/repos/dotnet/docs/deployments","created_at":"2015-05-19T15:13:32Z","updated_at":"2017-10-16T10:56:24Z","pushed_at":"2017-10-16T17:10:43Z","git_url":"git://github.com/dotnet/docs.git","ssh_url":"git@github.com:dotnet/docs.git","clone_url":"https://github.com/dotnet/docs.git","svn_url":"https://github.com/dotnet/docs","homepage":"https://docs.microsoft.com/dotnet","size":444445,"stargazers_count":694,"watchers_count":694,"language":null,"has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1405,"mirror_url":null,"open_issues_count":322,"forks":1405,"open_issues":322,"watchers":694,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dotnet/docs/pulls/3403"},"html":{"href":"https://github.com/dotnet/docs/pull/3403"},"issue":{"href":"https://api.github.com/repos/dotnet/docs/issues/3403"},"comments":{"href":"https://api.github.com/repos/dotnet/docs/issues/3403/comments"},"review_comments":{"href":"https://api.github.com/repos/dotnet/docs/pulls/3403/comments"},"review_comment":{"href":"https://api.github.com/repos/dotnet/docs/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dotnet/docs/pulls/3403/commits"},"statuses":{"href":"https://api.github.com/repos/dotnet/docs/statuses/8a9f4de9d54a7c037e3b137ab5c9002ae02c3255"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"rpetrusha"}}