Welcome to Andrew's Primer!

By: Andrew

The Language of C Sharp

C# is designed as a platform used as a language primarily on windows. Is also similar to C and C++. This languge what developed by a team led by Anders Hejlsberg, Also It was developed by Microsoft within its .NET initiative and later approved as a standard by Ecma (ECMA-334) and ISO (ISO/IEC 23270:2006). C# is one of the programming languages designed for the Common Language Infrastructure.
Most recent version of C# is 5.0, which was released on August 15, 2012. The name C Sharp was named after the written music note of a high pitch

Creating a Windows Application Program

1. Start by creating a new project using the file menu, than clicking project
2. In the list of programs you can create, Click on Windows Form Application
3. Keep or change the loction you want to save the project to
4. Than name your project what you want, Than click OK
5. If Solution Explorer is not open as a tag, Click on the View menu, Than click Solution Explorer.
6. If you need the toolbox, Click the view menu, Than click the toolbox and a screen will open up

Creating a Console Program

1. Start by creating a new project
2. In the list of programs you can choose from, Continue by Clicking on the Console Application Program
3. Than give the project a name and a loction that you want to save it to
4. Then you should be on a screen that shows "static void Main(string[] args)" as the first line of code
5. After you see that then you can start by 6.

How to create a Console Output

Console.WriteLine("Hello World!");

When you first start your console program the first line of code would be something like

Console

In this line the word Console is where a separate window show up and display the message "Hello World".

.Writeline

.Writeline a action for the console window to write the line of text.

How to create a Windows Output

1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Linq;
7 using System.Text;
8 using System.Windows.Forms;
9
10 namespace demoVariables
11 {
12 public partial class Form1 : Form
13 {
14 public Form1()
15 {
16 InitializeComponent();
17 }
18
19 private void btnPress_Click(object sender, EventArgs e)
20 {
21
22 }
23 }
24 }

Declaring an Integer Variable

Int32 intVar;

Initializing an Integer Variable

intVar = -47;

Boolean


Boolean variables can only store two states - True/False

Boolean blnVar;

Using this code will declare the program to keep some memory for it.

blnVar = true; Or blnVar = false;

Now you are using the code to set a value

Integer (-3,-2,-1,0,1,2,3)

Integers are a values for counting or answering the equations, without the addition of a decimal number.

Floating Point, Decimal Numbers & Double precision floating-point number.

Declaring an Decimal Variable

Double dblVar;

Initializing an Decimal Variable

dblVar = 301.235;

String

Strings are a combination of letters, numbers & punctuation

Declaring a String Variable

String strVar;

Initializing a String Variable

strVar = "hi";

Declaring and Initializing

Before you can use this variable you have to declare it & Initializing it. Combining is the best option for having only one small statement

String strVar = "hi";

Console input

1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5
6 namespace demoConsoleInput
7 {
8 class Program
9 {
10 static void Main(string[] args)
11 {
12 Console.WriteLine("What is your name?");
13 String strName;
14 strName = Console.ReadLine();
15 Int32 intAge;
16 Console.WriteLine("What is your age?");
17 while (!(Int32.TryParse(Console.ReadLine(), out intAge)))
18 {
19 Console.WriteLine("I'm sorry, age must be an integer.\nTry
again."); 20 }
21 Console.WriteLine(String.Concat(strName, " is ",
intAge.ToString(), " years old.")); 22 Console.ReadLine();
23 }
24 }
25 }

The input code above states that it needs data entered three times.
On line 17-20, the code will keep repeating until the user type in a integer that is required for the program to continue. In this case the console is asking for your age as the integer and if it does not receive it, it will keep asking for a integer.
On line 22, the program will not close until the user type a key or integer.

Windows Input

In order to create the windows input follow these nine steps.
1. Create a windows form program 2. In the toolbox menu, create a group box on your form 3. place three radio buttons to your grouo box 4. pick the selected items and renamed them in properties menu 5. add in the following: A Label, A textBox & A RichTextBox 6. Double-click the btnRun button. 7. See the following code:

private void btnRun_Click(object sender, EventArgs e)
{
}

8. Change that code to the following

private void btnRun_Click(object sender, EventArgs e)
{
if (rdbLarge.Checked)
rtbOutput.Text = String.Concat(txtName.Text, " ordered a large");
if (rdbMedium.Checked)
rtbOutput.Text = String.Concat(txtName.Text, " ordered a medium");
if (rdbSmall.Checked)
rtbOutput.Text = String.Concat(txtName.Text, " ordered a small");
}

Basic math operations

Adding and Subtracting
The following code demonstrates adding and subtraction of integers:

1 Int32 x = 4;
2 Int32 y = 2;
3 Int32 adding;
4 adding = x + y;
5 Console.WriteLine(String.Concat(x.ToString(), "+", y.ToString(), "=",
adding.ToString()));
6 Int32 subtracting;
7 subtracting = x - y;
8 Console.WriteLine(String.Concat(x.ToString(), "-", y.ToString(), "=",
subtracting.ToString()));
9 Console.ReadKey();

Multiplying and Dividing
The following code demonstrates multiplying and dividing of two doubles

1 Double x = 4.25;
2 Double y = 5;
3 Double multiplying;
4 multiplying = x * y;
5 Console.WriteLine(String.Concat(x.ToString(), "*", y.ToString(), "=",
multiplying.ToString()));
6 Double dividing;
7 dividing = x / y;
8 Console.WriteLine(String.Concat(x.ToString(), "/", y.ToString(), "=",
dividing.ToString()));
9 Console.ReadKey();

Concatenating Strings

Instead of adding or subtracting number, you can add names together like your first and last name. By having two string put together, which will hava a out come of Ian McTavish.

String strFName = "Ian";
String strLName = "McTavish";
Console.WriteLine(String.Concat(strFName, " ", strLName));

Works Cited – with at least two or three citations in MLA style

"CSS Tutorial." CSS Tutorial. N.p., n.d. Web. 28 Sept. 2014.
"Sign in - Google Accounts." Sign in - Google Accounts. N.p., n.d. Web. 28 Sept. 2014.
"EasyBib: The Free Automatic Bibliography Composer." EasyBib. N.p., n.d. Web. 28 Sept. 2014.