3. SHARE OUT
1. 3 job postings for the companies you want to work for
2. Research what qualifications you need to get that job
3. The company culture of the 3 companies you chose
4. Project ideas to add onto your resume
4. AGENDA
• Creating Projects Within Visual Studio 2010
• Explain the structure of a C# application.
• Writing a C# Application
• Print statements + Variables + Error Handling
• Documenting an Application
• Running and Debugging Applications by Using Visual Studio 2010
6. PARTS OF A C#
PROJECT
• Solution: a container used by Visual
Studio to organize one or more related
projects.
• When you open a solution in
Visual Studio, it automatically
loads all the projects that the
solution contains.
• Workspace: This is the space where
you actually work on a part of your
program.
10. COMPILING VS RUNNING
• Compile-time is the time at which the source code is converted into an
executable code (converting from C# language to byte language – the computer
understands byte language)
• Run time is the time at which the executable code has started running i.e. your
output begins producing.
11. STRUCTURE OF A C# APPLICATION
• The first line of the program using System; - the using keyword is used to include the System namespace in the
program. A program generally has multiple using statements.
• The next line has the namespace declaration. A namespace is a collection of classes.
The HelloWorldApplication namespace contains the class HelloWorld.
• The next line has a class declaration, the class HelloWorld contains the data and method definitions that your
program uses. Classes generally contain multiple methods. Methods define the behavior of the class. However,
the HelloWorld class has only one method Main.
• The next line defines the Main method, which is the entry point for all C# programs. The Main method states what
the class does when executed.
• The next line /*...*/ is ignored by the compiler and it is put to add comments in the program.
• The Main method specifies its behavior with the statement Console.WriteLine("Hello World");
• WriteLine is a method of the Console class defined in the System namespace. This statement causes the message
"Hello, World!" to be displayed on the screen.
• The last line Console.ReadKey(); is for the VS.NET Users. This makes the program wait for a key press and it
prevents the screen from running and closing quickly when the program is launched from Visual Studio .NET.
13. PRINT STATEMENTS
• Console.WriteLine(“your text”);
• After the console prints your text, the cursor will start on a new line
• Console.Write(“your text”);
• After the console prints your text, the cursor will stay on the same line
14. VARIABLES – 5 DIFFERENT DATA TYPES
• int - integers (whole numbers) such as 0, -65
• double - decimals such as 19.99 or -19.99
• char - characters such as 'a' or 'B'. Char values are surrounded by single quotes
• string - text, such as "Hello World". String values are surrounded by double
quotes
• bool - Boolean such as true or false
15. VARIABLE SYNTAX
• type variableName = value; int myNum = 15;
myNum = 20; // myNum is now 20
Console.WriteLine(myNum);
int myNum = 15;
myNum = 20; // myNum is now 20
Console.WriteLine(myNum);
int myNum;
myNum = 15;
Console.WriteLine(myNum);
string name = ”Ruby";
Console.WriteLine(name);
16. CONCATENATION
• Concatenation: Combining a string with a variable
string name = "John";
Console.WriteLine("Hello " + name);
string firstName = "John ";
string lastName = "Doe";
string fullName = firstName + lastName;
Console.WriteLine(fullName);
17. MORE EXAMPLES …
int x = 5;
int y = 6;
Console.WriteLine(x + y); // Print the value of x + y
int x = 5, y = 6, z = 50;
Console.WriteLine(x + y + z);
18. MEANINGFUL NAMES
// Good
int minutesPerHour = 60;
// OK, but not so easy to understand what m actually is
int m = 60;
19. ERROR HANDLING
• An exception is a problem that happens during the execution of a program.
• try − A try block identifies a block of code for which particular exceptions is activated. It is
followed by one or more catch blocks.
• catch − A program catches an exception with an exception handler at the place in a program
where you want to handle the problem. The catch keyword indicates the catching of an
exception.
• finally − The finally block is used to execute a given set of statements, whether an exception is
thrown or not thrown. For example, if you open a file, it must be closed whether an exception is
raised or not.
• throw − A program throws an exception when a problem shows up. This is done using a throw
keyword.
20.
21.
22. WHY IS COMMENTING IMPORTANT?
• For you to understand X amount of time later
• For your colleagues to understand (marketing, development, etc.)
• Can make code maintenance much easier, as well as helping make finding bugs
faster.
• Clients are able to use your code efficiently
• Organization
23. WHAT IS COMMENTING?
• All programs should be commented in such a manner as to easily describe (in English) the
purpose of the code and any algorithms used to accomplish the purpose.
• A user should be able to utilize a previously written program (or function) without ever having to
look at the code, simply by reading the comments.
• Commenting is the "art" of describing what your program is going to do in "high level" English
statements. Commenting is best done before actually writing the code for your program.
• Comments are specially marked lines of text in the program that are IGNORED.
• There are usually two syntactic ways to comment.
• The first is called a single line comment and, as implied, only applies to a single line in the "source
code" (the program).
• The second is called a Block comment and refers usually refers to a paragraph of text. A block comment
has a start symbol and an end symbol and everything between is ignored by the computer
24. HOW TO COMMENT CODE
INCLUDE
• what the function does.
• what arguments the function
expects.
• any known issues with the code.
• up-to-date information.
Information about code that has
since been changed is of no use
to anyone.
• credit where credit is due.
Make sure to credit anyone who
contributed to the code!
AVOID
• unnecessary information.
Don’t include anything not related to the code and
avoid over explaining.
• assuming the user’s knowledge.
The documentation needs to be helpful to everyone,
from experts to beginners.
• confusing formatting.
Doesn’t matter how much information is in the
documentation if no one can read it.
• ambiguous or hard to understand language.
Documentation has been standardized to be written
in English, so it is going to be used by non-native
speakers of English as well.
NOT HOW but… WHAT
25. DOCUMENTING YOUR CODE (COMMENTS)
/* The code below will print the words Hello World to
the screen, and it is amazing */
Console.WriteLine("Hello World!");
// This is a comment
Console.WriteLine("Hello World!");
26. HOW TO COMMENT YOUR FILES
• The first four lines of any program:
• Full Name:
• Date:
• File Name:
• Purpose:
29. SET A BREAKPOINT AND START THE DEBUGGER
• Set a breakpoint and start the debugger
• F5 (Debug > Start Debugging) or the Start Debugging button in the debug toolbar
• The debugger runs to the first breakpoint that it encounters. If the app is not yet
running, F5 starts the debugger and stops at the first breakpoint.
• A breakpoint indicates where Visual Studio should suspend your running code so
you can take a look at the values of variables, or the behavior of memory, or
whether or not a branch of code is getting run.
• You can set a breakpoint by clicking in the margin to the left of a line of code.
32. INSPECT VARIABLES WITH THE AUTOS AND LOCALS
WINDOWS
• While debugging, look at the Autos window at the bottom of the code editor.
• In the Autos window, you see variables along with their current value and their
type.
• The Autos window shows all variables used on the current line or the preceding
line
33. • Next, look at the Locals window. The Locals window shows you the variables that
are currently in scope.
34. • You can use a Watch window to specify a
variable (or an expression) that you want
to keep an eye on.
• While debugging, right-click an object
and choose Add Watch.
• In this example, you have a watch set on
the f object, and you can see its value
change as you move through the
debugger.
• Unlike the other variable windows,
the Watch windows always show the
variables that you are watching (they're
grayed out when out of scope).
35. EXAMINE THE CALL STACK
• The Call Stack window shows the order in which methods and functions are
getting called.
• The top line shows the current function (the Update method in this example).
• The second line shows that Update was called from the Path.set property, and so
on.
• The call stack is a good way to examine and understand the execution flow of an
app.
36. EXAMINE AN EXCEPTION
• When your code throws an exception, the debugger takes you to the line of code
that threw the exception.
• In this example, the Exception Helper shows you a System.Argument exception
and an error message that says that the path is not a legal form.
• So, we know the error occurred on a method or function argument.
37.
38. DISCUSSION
• Why is this important?
• How can this be useful to me?
• How can I use this in my current
job?
• How can I use this in my future
career?
• What will I get out of this?
• How is this used in the real world
Regroup and discuss after…