Open main menu

Editing C-Sharpe

Warning: The database has been locked for maintenance, so you will not be able to save your edits right now. You may wish to copy and paste your text into a text file and save it for later.

The system administrator who locked it offered this explanation: We are placing MPGH Wiki into a read-only state. If you are interested in contributing content towards this Wiki please contact Silent on MPGH.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

Latest revision Your text
Line 1: Line 1:
C# Is a modern, object-orientated programming (OOP) language created by Microsoft in 2002 for their all new .NET Framework. Since '02, C# has been used across many frameworks for all different types of platforms. For example; Windows has .NET Framework; Andoird & IOS have [https://www.xamarin.com/ Xamarin]; Windows, OSX, and Linux have [http://www.mono-project.com/ Mono]. There are other frameworks that support C#, but they're less known.
+
C# Is a modern, [[OOP|object-orientated programming (OOP)]] language created by Microsoft in 2002 for their all new .NET Framework. Since '02, C# has been used across many frameworks for all different types of platforms. For example; Windows has .NET Framework; Andoird & IOS have [https://www.xamarin.com/ Xamarin]; Windows, OSX, and Linux have [http://www.mono-project.com/ Mono]. There are other frameworks that support C#, but they're the well known.
 
 
Note: Everything below assumes you're using windows.
 
 
 
 
 
 
 
== This is all WIP and hasn't been read over ==
 
  
  
Line 13: Line 7:
  
  
== Hello World & Visual Studio Introduction ==
+
== Hello World ==
  
 
=== Creating Project ===
 
=== Creating Project ===
 
First lets open Visual Studio. Upon opening you will be shown a page like [https://s.msger.us/i/3c391f310ArY.png this (image)]. Mine might be slightly different because I'm using an outdated version of Visual Studio. Okay, so now we want to create a new project. This can be done through the File button at the top left, or at the New Project button in the Start Page tab. [https://s.msger.us/i/3c74217fjCFz.png Image]. When clicking that button, a window like [https://s.msger.us/i/3cad1cab4rR3.png this (image)] will appear. At this screen you can pick your desired programming language, type of project, and the project's name. We want to select Visual C# for the language, for the type we want a Console Application. Your screen should look like [https://s.msger.us/i/3cad1cab4rR3.png this] if you followed the instructions correctly. Now we want to click OK.
 
First lets open Visual Studio. Upon opening you will be shown a page like [https://s.msger.us/i/3c391f310ArY.png this (image)]. Mine might be slightly different because I'm using an outdated version of Visual Studio. Okay, so now we want to create a new project. This can be done through the File button at the top left, or at the New Project button in the Start Page tab. [https://s.msger.us/i/3c74217fjCFz.png Image]. When clicking that button, a window like [https://s.msger.us/i/3cad1cab4rR3.png this (image)] will appear. At this screen you can pick your desired programming language, type of project, and the project's name. We want to select Visual C# for the language, for the type we want a Console Application. Your screen should look like [https://s.msger.us/i/3cad1cab4rR3.png this] if you followed the instructions correctly. Now we want to click OK.
 
  
 
=== Breakdown of what you see ===
 
=== Breakdown of what you see ===
Line 23: Line 16:
  
  
==== Topbar ====
+
.. add  more
[[File:Vs sidebar.png|1000px]]
 
 
 
We will not breakdown everything on this bar just yet, it will just introduce confusion. The only thing on this bar that a relevant to us right now is the start button and save button.
 
 
 
==== Solution Explorer ====
 
[[File:Vs solution explorer.png]]
 
 
 
By default, this is located on the right of your screen. Solution Explorer has a full layout of your projects files, properties, and dependencies. The properties tree-index by default has a file called AssemblyInfo.cs. AssemblyInfo.cs has information about the application after you have compiled it. We can just leave AssemblyInfo in its default state. The references tree-index has a list of your projects dependencies. This will not be needed right now. The App.config has pre-runtime information that can tell windows information about the executable. This can also be ignored.
 
 
 
Now we got the boring things out of the way, we're up to the Program.cs file. This is where your main entry point is. What is our main entry point? It's the first chunk of code that's executed. Program.cs will be our main focus.
 
 
 
 
 
==== Code Editor ====
 
[[File:Vs text editor.png]]
 
 
 
This is basically where we edit out code. You can have multiple tabs, you can merge tabs together by simply dragging the tab. No further explanation required.
 
 
 
 
 
=== Making our Hello World code ===
 
 
 
 
 
Okay, now we've done the very basic Visual Studio introduction, we can make the Hello World code. This will be very basic, we will simply output the text "Hello World" to the console, then wait for user input. So to output text we can use either call the function Console.WriteLine or Console.Write. What's the difference between the two functions? Console.WriteLine will create a new line after the text we output, and Console.Write requires us to manually output the new line. For simplicity, we will use Console.WriteLine. When I described what we want the Hello World program to do, I said output Hello world, then wait for user input. So when listening for user input, we can use Console.ReadLine or Console.ReadKey. Console.ReadLine returns a value, a string, while Console.ReadKey doesn't return anything, it simply waits for a user to press any key then the program will continue on its way.
 
 
 
 
 
==== Program.cs explanation ====
 
'''- Now I'll begin to explain the default code in Program.cs.'''
 
<br />
 
We want to go over to our IDE (Visual Studio) and locate the Program.cs file in the Solution Explorer. Double click it, and you will be shown the main project file that has the entry point. In this Program.cs file, you will see a few things. Up the top you can see your namespace includes. Namespace includes basically let you include other files, or dependencies. A little under that we can see the namespace of the current file, it will be 'namespace HelloWorld'. Then it will have a block of code. What is a block of code? It's basically all the text between '{' and '}'. '{' is the opening tag, '}' is the closing tag. Within the namespace block of code, we will have the class name, which will be 'class Program' which also has a block of code. Within the Program class block of code, there is our main function. The main function is where we put our code.
 
 
 
==== Adding our code ====
 
'''- Placing our code in main function.'''
 
<br />
 
So, now we simply want to put our WriteLine function and ReadKey function in the main functions block of code (aka entry point). Lets put Console.WriteLine passing the parameter "Hello World," that will look like Console.WriteLine("Hello World");. This is enough to run our application, but it will instantly close. To prevent the closing, we must wait for user input. To wait for user input, put Console.ReadKey(); after the writeline.
 
 
 
 
 
==== Our code ====
 
Explanation of code, blocks, and other things [https://s.msger.us/i/3cf31d6cL3Zm.png click here (image)]
 
 
 
<code>
 
    using System;
 
    using System.Collections.Generic;
 
    using System.Linq;
 
    using System.Text;
 
    using System.Threading.Tasks;
 
    namespace HelloWorld
 
    {
 
        class Program
 
        {
 
            static void Main(string[] args)
 
            {
 
                Console.WriteLine("Hello World");
 
                Console.ReadKey();
 
            }
 
        }
 
    }
 
</code>
 
 
 
(sorry about the broken code tags)
 
 
 
==== Complete Hello World ====
 
[[File:Csharpe project view.png|670px]]
 

Please note that all contributions to MPGH Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see MPGH-Wiki:Copyrights for details). Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)