Documente Academic
Documente Profesional
Documente Cultură
NET Fundamentals
Week 1
November 6, 2003
Introduction
• Chip Schopp
• www.pondviewsoftware.com
• chipschopp@comcast.net
• (978) 779-5126
Class Schedule – November 6, 2003
• Introductions and other beginning stuff…
• Review Class Syllabus / Class Goals
• Class Dates
• Introduction to .NET
• Introduction to C#
• Class Exercise(s)
• Homework Assignment
.Net Fundamentals
CT-186
Text Books
8
Class Goals
• Provide an overview of the .NET Architecture
with Major Components
• Programming Languages
• ADO.NET
• ASP.NET
• Web Services
• XML Integration
Class Goals
13
Class Dates
• Class Dates ( 6, 7, or 8 classes ?)
• November 6, 13, 20 – December 4, 11, 18
• November 27, Thanksgiving, no class
• Other possible dates:
• Monday November 24th
• Monday December 1st
• Monday December 8th or Tuesday December 9th
• Monday December 15th or Tuesday December 16th
• Or ?
Effective Learning
• First is Doing
• Class exercises
• Coaching
• Helping each other
• Homework
• Second is Discussing
• Class discussions
• Asking questions
• Sharing ideas and information
• Last is Listening
15
Learning Environment
Programming is Fun!
The only dumb questions
are the ones not asked!
17
Time to Address Open Questions
18
Your introductions
• Programming background
• Operating systems, languages
• Any exposure to .NET ? Other courses ?
• What do you expect to get out of this course ?
Please email me the following…
• Full Name, Nick Name, Student ID #
• Home Phone / Work Phone
20
Email Address (s) [email gives me
one]
• Your background in computing/programming
• Any experience with .NET, other courses, ?
• Your objective or goals for this course
• Any material you have a special interest in
covering?
• Any issues or questions that you have?
• Additional dates you can attend classes on.
21
22
What Is the Microsoft .NET
Framework?
The Microsoft® .NET Framework is an
important new component of the
Microsoft Windows® family of operating
systems. It is the foundation of the next
generation of Windows-based
applications that are easier to build,
deploy, and integrate with other
networked systems.
23
The .NET Initiative
25
What Is the Microsoft .NET
Framework?
The .NET Framework helps software
developers and systems administrators
more easily build and maintain systems
with improvements toward performance,
security, and reliability. Here's how.
26
A New Approach to Building
Windows Software
The .NET Framework simplifies Windows
software development. It provides developers
with a single approach to build both desktop
applications—sometimes called smart client
applications—and Web-based applications. It
also enables developers to use the same tools
and skills to develop software for a variety of
systems ranging from handheld smartphones
to large server installations.
27
A New Approach to Building
Windows Software
Software built on the .NET Framework
can be easier to deploy and maintain
than conventional software. Applications
can be designed to automatically
upgrade themselves to the latest
version. The .NET Framework can also
minimize conflicts between applications
by helping incompatible software
components coexist.
28
Benefits of the .NET
Framework
• Helps IT professionals better integrate
existing systems with its native support for
Web services.
• Assists with the deployment of software to
both users and Web servers.
• Facilitates the development of software with
improved reliability, scalability, performance,
and security.
29
Helps developers be more
productive by:
• Making it easier for them to reuse existing
code.
• Enabling them to more easily integrate
components written in any of the more than
20 supported programming languages.
• Helping them more easily build software for
a wide range of devices using same skills
and tools.
30
The Development Environment –
Visual Studio.NET
• Finally , Visual Studio truly becomes an
Integrated Development Environment, with
multi-language development.
• Runs on Windows 2000, NT, XP and the .NET
server family.
• Support for building 32 and 64 bit applications
• Usual gamut of wizards, debuggers, linkers…
• Plenty of good documentation
• Free .NET Framework SDK – compilers, tools,
documentation
The Development/Runtime
platform – the .NET Framework
• The new runtime environment in .NET
• Provides a set of base classes for
developers to build on
• A unified type system to allow language
inter-operability
• This course deals with the fundamentals of
programming this framework
To summarize, .NET is…
• An OS platform
• The .NET Enterprise Servers.NET building
block services
• .NET Device Software
• The Development Environment – Visual
Studio.NET
• The Development/Runtime platform –
the .NET Framework
The .NET Framework
Windows
Mouse Scanner
Driver Driver
The .NET Framework
• If we abstract the underlying OS in the
same way…
Application
.NET Framework
44
The heart of the Framework
• The most important elements of the
franework are:
• The Common Language Runtime (CLR)
• The Framework Class Libraries (FCL)
ASP.NET WinForms
48
Managed Code
Code executed and managed by the Microsoft® .NET
Framework, specifically by the .NET Framework's
common language runtime.
Managed code must supply the information necessary
for the common language runtime to provide services
such as memory management, cross-language
integration, code access security, and automatic
lifetime control of objects.
All code based on Microsoft Intermediate Language
executes as managed code.
.NET Framework Class Library
56
• Create a Working Directory
mkdir k:\week1\hello
• Copy corvars.bat
copy
c:\Program Files\Microsoft Visual Studio.NET
\FrameworkSDK\bin\corvars.bat
k:\week1\hello\corvars.bat
• Set up environment, run covars.bat
Cd k:\week1\hello
Type corvars.bat <hit return>
57
Open notepad, create the following file and
save it in the k:\week1\hello directory as
hello.cs.
class Hello
{
static void Main()
{
System.Console.WriteLine("Hello World");
}
}
• Compile the program
k:\week1\hello>csc Hello.cs
59
60
C#.NET Language Basics
•Types in C#
•Defining integer types
•A Bit About Strings
•Reading From and Writing To The Console
•If Then Statement
•Looping – The For Next Statement
61
Primitive Types
bool System.Boolean
byte System.Byte
sbyte System.Sbyte
char System.Char
decimal System.Decimal
double System.Double
float System.Single
Primitive Types (contd.)
int System.Int32
uint System.UInt32
long System.Int64
ulong System.UInt64
object System.Object
short System.Int16
ushort System.UInt16
string System.String
A word on types
• All types in .NET derive from System.Object
• They are provided implementations of ToString()
and GetType()
• To get a string with the type of any variable, you
can call <var>.GetType()
• Whenever you call Console.WriteLine(obj) the
ToString() method on obj is implicitly called. The
default ToString implementation for classes simply
returns the name of the class.
What Are Integers
0, 432, -5, 10000000, -10000000
Integers are whole numbers
67
What are strings?
“abcdef” “Abcdef” “aBcdEf” “A23+-/*789” “q”
“John J. Smith”
“How do you do?”
“123 South Street, Calais, ME 04235”
“ Are we there? ”
“” an empty string
How do we define strings?
string strTmp;
strTmp = “time will tell”;
string strTmp = “time will tell”;
strTmp = Console.ReadLine();
string strTmp2;
strTmp2 = strTmp;
strTmp2 “time will tell”
Concatenating Strings
string strCity = “Calais”;
string strState = “ME”;
string strZip = “04270”;
string strLoc;
strLoc = strCity + “, ” + strState + “ ” + strZip;
strLoc “Calais, ME 04270”
Some String Functions
string strTmp;
strTmp.Trim(); – removes leading and trailing spaces
strTmp.ToUpper(); – converts string to all upper case
strTmp.ToLower(); – converts string to all lower case
strTmp.Length; – returns string length as an integer
strTmp.SubString() – extracts a substring
String Function Examples
string strTmp;
strTmp = “in the beginning”;
The value of strTmp.Length is 16.
int i;
i = strTmp.Length;
== is for equivalence
if (str1 == str2) { some code }
if (str.Length == 0) { some code }
if (str1 != “end”) { some code }
79
Sample if Statement
string strInput ;
strInput = Console.ReadLine();
if (strInput == “”)
{
Console.WriteLine(“Input required.”);
}
The For Loop
81
A Simple For Loop
int i;
for (i = 1; i<10; i++)
{
Console.WriteLine("The value of i is " + i.ToString());
}
The Value of i is 1
The Value of i is 2
The Value of i is 3
…
The Value of i is 9
The Value of i is 10
Or You Could Reverse It…
int i;
for (i = 10; i>0; i--)
{
Console.WriteLine("The value of i is " + i.ToString());
}
The Value of i is 10
The Value of i is 9
The Value of i is 8
…
The Value of i is 2
The Value of i is 1
To Walk Through a String
goto Statements
goto Statements Direct Program Flow To A Label
goto ReturnHere;
if (tmpStr.Length == 0)
{
Console.WriteLine(“No String Entered”);
goto ReturnHere;
}
if (strTmp == “end”)
{
return;
}
Note: return tells the program to exit the subroutine, which in this
case will end the program.
Comments in C#
91
92
Now let’s redo hello.cs as a
Visual Studio project.
93
Visual Studio.NET
• The newest version of Visual Studio
• Multiple language development finally in one
environment.
• Can program in
• Visual C#
• Visual Basic.NET
• Visual C++.NET
• Can build
• Desktop console and GUI applications
• Web services
• ASP.NET Web applications
• Mobile applications
To get Visual Studio.NET
namespace HelloVS
{
/// <summary>
/// Summary description for App.
/// </summary>
class App
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
System.Console.WriteLine("Hello World");
}
}
}
Class Exercise (time permitting)
Using the Visual Studio.NET write an interactive
console program to accept information from the
keyboard and then format and display the
information back. It might be a person’s name and
address or a variable list of favorite pets including
name and type of animal or whatever. Focus on
formatting the data, looping to accept multiple
entries, testing for missing information and also
testing for an at end condition. A sample, somewhat
simplified example is in the Class Collections zip file
on the web (i.e. www.PondviewSoftware.com).
98
99
Homework Part 1
Send Me An Email ChipSchopp@comcast.net, include the
following:
1. Full Name, Nick Name, Student ID #
2. Home Phone / Work Phone
3. Email Address (s) [email gives me one]
4. Your background in computing/programming
5. Any experience with .NET, other courses, ?
6. Your objective or goals for this course
7. Any material you have a special interest in covering?
8. Any issues or questions that you have?
9. Which additional dates you would attend classes on.
Homework Part 2
C#.Net Programming
Homework Assignment – Week 1
Assignment Due: November 13, 2003 5:30 PM
101
Write a C#.NET Console Application, which
performs the following:
1. Accepts a first name string, a middle name string, and a last name
string from the console. The first name and last name are required.
The middle name is optional.
2. Concatenates the two or three fields together creating a full name
string.
3. Truncates the full name to 20 characters if the length of the full name
is longer than 20 characters.
4. Provides the capability of displaying the full name either vertically or
horizontally and forward or backward as desired.
5. Allows the full name field to be displayed in either of these four ways
as many times as desired.
6. Allows the user to go back to the top and start over, entering a new
name.
7. Terminates gracefully.
Note:
There was enough information discussed in today’s class to complete
this assignment. Feel free to use any additional commands,
102
structures, or functions you wish.
103