Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
C# and the NET Platform, Second Edition - Andrew Troelsen.pdf
Скачиваний:
67
Добавлен:
24.05.2014
Размер:
22.43 Mб
Скачать

Defining Program Constants

 

C# and the .NET Platform, Second Edition

 

by Andrew Troelsen

ISBN:1590590554

Now that you can create (and transform) value-based and reference-based variables, you need to examine the

Apress © 2003 (1200 pages)

logical opposite: Constants. C# offers the "const" keyword, to define variables with a fixed, unalterable value.

This comprehensive text starts with a brief overview of the

Unlike C++, the C#C#"const"languagekeywordand thencannotquicklybemovesused toto qualifykey technicalparametersand or return values. Furthermore, it is important to understandarchitecthaturaltheissuesvalueforof.NETa constantdeveloperspoint. of data is computed at compile time, and therefore a constant member cannot be assigned to an object reference (whose value is computed at runtime). Although it is possible to define local constants within a method scope, a more beneficial use of const is to create class-

Table of Contents

level constant definitions. For example:

C# and the .NET Platform, Second Edition

Introduction

// Some const data.

Part One - Introducing C# and the .NET Platform

using System;

Chapter 1 - The Philosophy of .NET

class MyConstants

Chapter 2 - Building C# Applications

{

Part Two - The C# Programming Language

// When accessed by another type, these constants

Chapter

3

- C# Language Fundamentals

 

 

// must be referenced via the fully qualified name.

Chapter

public const int myIntConst = 5;

4

- Object-Oriented Programming wi h C#

Chapter

5

- Ex eptions and Object Lifetime

 

 

public const string myStringConst = "I'm a const";

Chapter public6 - Interfacesstaticand vCollectionsid Main()

 

Chapter {7

- Callback Interfaces, Delegates, and Events

Chapter

8

- Advanced// ScopedC# Typeconstant.Construction Techniques

Part Three - Programmingconst stringwith .NETlocalConstAssemblies = "I am a rock, I am an island";

Chapter

9

- Understanding// Use const.NET Assembliesdata.

 

Chapter

10

- Processes,Console.WriteLine("myIntConstAppDomains, Contexts, and Threads= {0}\nmyStringConst = {1}",

Chapter

11

- Type Reflection, Late Binding,myIntConst,and Attribute-BasedmyStringConst);Programming

Part Four - LeveragingConsole.WriteLine("Localthe .NET Libraries

constant: {0}", localConst);

Chapter }12

- Object Serialization and the .NET Remoting Layer

Chapter}

13

- Building a Better Window (Introducing Windows Forms)

Chapter

14

- A Better Painting Framework (GDI+)

 

Chapter

15

- Programming with Windows Forms Controls

If you create a utility class that contains nothing but constant data, you may wish to define a private constructor.

Chapter

16

- The Sy tem.IO Namespace

 

In this way, you ensure the object user cannot make an instance of your class (which would be desirable given

Chapter

17

- Data Access with ADO.NET

 

that the class has no real implementation):

 

Part Five - Web Applications and XML Web Services

Chapter

18

- ASP.NET Web Pages and Web Controls

// Private constructors prevent the creation of a given type.

Chapter

19

- ASP.NET Web Applications

 

class MyConstants

 

Chapter

20

- XML Web Services

 

{

public const int myIntConst = 5;

Index

List of Figurespublic const string myStringConst = "I'm a const";

List of Tables// Don't let the user make this class,

// as its only purpose is to define constant values.

private MyConstants(){ }

}

The same result can be achieved by marking your "constant-only class" as an abstract type. You examine the use of this keyword in the next chapter, but here is the updated MyConstants definition:

// Abstract definition also prevents the creation of a given type.

abstract class MyConstants

{

public const int myIntConst = 5;

public const string myStringConst = "I'm a const";

}

In either case, if another object attempts to create an instance of MyConstants, a compiler error is generated.

C# and the .NET Platform, Second Edition

These techniques can be quite helpful given that C# does not allow you to define global level constants. by Andrew Troelsen ISBN:1590590554

Apress © 2003 (1200 pages)

Referencing Constant Data Across Types

This comprehensive text starts with a brief overview of the

C# language and then quickly moves to key technical and

Given that we havearchitecturalmoved ourissuesconstantfor .NETpointsdevelopersof data into. a new class definition, how are they accessed from within another type? If you attempt to simply reference them by their unqualified name (myIntConstant, myStringConstant) you will be issued a compiler error. Again, the reason has to do with the fact that under C#,

TableglobalofpointsCo tentsof data are not allowed. Thus, any time you wish to access a constant defined outside of the

C#defininga d theclass,.NETyouPlatform,must Secondmake useEditionof the fully-qualified name. On the other hand, if a given class wishes to

Introductionaccess a constant it directly defined, you are able to directly refer to the item at hand:

Part One - Introducing C# and the .NET Platform

Chapter 1 - The Philosophy of .NET

public static void Main()

Chapter 2 - Building C# Applications

{

Part Twoconst- The C#stringP ogramminglocalConstLanguage= "I am a rock, I am an island";

Chapter //3 -UseC# Languageconst dataFundamentals.

Chapter Consol4 - Object.WriteLine("myIntConst-Or ented Programming with C#= {0}\nmyStringConst = {1}\nLocalConst = {2}"

Chapter MyConstants5 - Exceptions.andmyIntConst,Object LifetimeMyConstants.myStringConst, localConst);

}

Chapter 6 - Interfaces and Collections

Chapter 7 - Callback Interfaces, Delegates, and Events

Chapter 8 - Advanced C# Type Construction Techniques

Part Three - Programming with .NET Assemblies

SOURCE The Constants project is located under the Chapter 3 subdirectory.

Chapter 9 - Understanding .NET Assemblies

CODE

Chapter 10 - Processes, AppDomains, Contexts, and Threads

Chapter 11 - Type Reflection, Late Binding, and Attribute-Based Programming

Part Four - Leveraging the .NET Libraries

Chapter 12 - Object Serialization and the .NET Remoting Layer

Chapter 13 - Building a Better Window (Introducing Windows Forms)

Chapter 14 - A Better Painting Framework (GDI+)

Chapter 15 - Programming with Windows Forms Controls

Chapter 16 - The System.IO Namespace

Chapter 17 - Data Access with ADO.NET

Part Five - Web Applications and XML Web Services

Chapter 18 - ASP.NET Web Pages and Web Controls

Chapter 19 - ASP.NET Web Applications

Chapter 20 - XML Web Services

Index

List of Figures

List of Tables

Chapter 6 - Interfaces and Collections
Chapter 5 - Exceptions and Object Lifetime

C# IterationC#Constructsand the .NET Platform, Second Edition

by Andrew Troelsen

ISBN:1590590554

Consider the next few pages a mid-chapter reprieve from the complexities of value/reference types,

Apress © 2003 (1200 pages)

overriding members of System.Object, and boxing types on the heap (in other words, the next few sections

This comprehensive text starts with a brief overview of the

are boring, but necessaryC# languageto cover)and then. Asquicklyyou aremoveswell aware,to key alltechnicalprogrammingand languages provide ways to repeat blocks of codearchitecturuntil alterminatingissues for .NETconditiondevelopershas .been met. Regardless of which language you are coming from, the C# iteration statements should pose no raised eyebrows and require little explanation. In a nutshell, C# provides the following four iteration constructs:

Table of Contents

C#andfortheloop.NET Platform, Second Edition

Introduction

foreach/in loop

Part One - Introducing C# and the .NET Platform

Chapter 1 - The Philosophy of .NET

while loop

Chapter 2 - Building C# Applications

Part Twodo/while- TheloopC# Programming Language

Chapter 3 - C# Language Fundamentals

C, C++, and Java programmers will no doubt be familiar with the "for," "while," and "do/while" loops, but

Chapter 4 - Object-Oriented Programming with C#

may be unfamiliar with the "foreach" statement. Visual Basic programmers on the other hand, are in the fortunate position to be well aware of all four C# iteration statements, as VB already supports "For Each"

syntax. Let's quickly examine each looping construct in turn.

Chapter 7 - Callback Interfaces, Delegates, and Events

Chapter 8 - Advanced C# Type Construction Techniques

The for Loop

Part Three - Programming with .NET Assemblies

Chapter 9 - Understanding .NET Assemblies

When you need to iterate over a block of code a fixed number of times, the "for" statement is the construct

Chapter 10 - Processes, AppDomains, Contexts, and Threads

of champions. In essence, you are able to specify how many times a block of code repeats itself, as well as

Chapter 11 - Type Reflection, Late Binding, and Attribute-Based Programming

the terminating condition. Without belaboring the point, here is a sample of the syntax:

Part Four - Leveraging the .NET Libraries

Chapter 12 - Object Serialization and the .NET Remoting Layer

// A basic for loop.

Chapter 13 - Building a Better Window (Introducing Windows Forms) public static int Main(string[] args)

Chapter 14 - A Better Painting Framework (GDI+)

{

Chapter 15 - Programming with Windows Forms Controls

// Note! 'i' is only visible within the scope of the for loop.

Chapter 16 - The System.IO Namespace for(int i = 0; i < 10; i++)

Chapter 17 - Data Access with ADO.NET

{

Part Five - Web Applications and XML Web Services

Console.WriteLine("Number is: {0} ", i);

Chapter 18 - ASP.NET Web Pages and Web Controls

}

Chapter 19 - ASP.NET Web Applications

// 'i' is not visible here.

Chapter 20 - XML Web Services

return 0;

Index}

List of Figures

List of Tables

All of your old C, C++, and Java tricks still hold when building a C# for statement. You can create complex terminating conditions, build endless loops, and make use of the "goto," "continue," and "break" keywords. I'll assume that you will bend this iteration construct as you see fit.

The foreach/in Loop

Visual Basic programmers have long seen the benefits of the For Each construct. The C# equivalent allows you to iterate over all items within an array. Here is a simple example using foreach to traverse an array of strings that represent possible titles for forthcoming publications. Once this array has been filled, you iterate over the contents looking for a pattern match (COM or .NET) using String.IndexOf():

// Digging into an array using foreach.

public static int Main(string[] args)

{

string[] arrBookTitles = new string[] {

"Complex Algorithms",

C# and the .NET Platform, Second Edition

by Andrew Troelsen

Apress © 2003 (1200 pages)

"COM for the Fearful Programmer",

"Do you Remember Classic COM?",

ISBN:1590590554

"C# and the .NET Platform",

"COM for the Angry Engineer" } ;

This comprehensive text starts with a brief overview of the int COM = 0, NET = 0;

C# language and then quickly moves to key technical and

// Assume we are not looking for books on COM interop. architectural issues for .NET developers.

foreach (string s in arrBookTitles)

{

if (-1 != s.IndexOf("COM"))

Table of Contents

COM++;

C# and the .NET Platform, Second Edition

else if(-1 != s.IndexOf(".NET"))

Introduction

NET++;

Part One - Introducing C# and the .NET Platform

}

Chapter 1 - The Philosophy of .NET

Console.WriteLine("Found {0} COM references and {1} .NET references.",

Chapter 2 - Building C# Applications

COM, NET);

Part Two - The C# Programming Language

return 0;

Chapter 3 - C# Language Fundamentals

}

Chapter 4 - Object-Oriented Programming with C# Chapter 5 - Exceptions and Object Lifetime

ChapterIn addition6 -toIntiteratingfaces overand Collectionssimple arrays, foreach is also able to iterate over system-supplied or user-

defined collections. I'll hold off on the details until Chapter 6, as this aspect of the "foreach" keyword entails

Chapter 7 - Callback Interfaces, Delegates, and Events

an understanding of interface-based programming and the system-supplied IEnumerator and IEnumerable

Chapter 8 - Advanced C# Type Construction Techniques

interfaces.

Part Three - Programming with .NET Assemblies

Chapter 9 - Understanding .NET Assemblies

ChaptTherwhile10 - Processes,and do/whileAppDoma ns, Contexts,Loopingand ThreadsConstructs

Chapter 11 - Type Reflection, Late Binding, and Attribute-Based Programming

You have already seen that the for statement is typically used when you have some foreknowledge of the

Part Four - Leveraging the .NET Libraries

number of iterations you wish to perform (e.g., loop until j > 20). The while statement on the other hand is

Chapter 12 - Object Serialization and the .NET Remoting Layer

useful for those times when you are uncertain how long it might take for a terminating condition to be met.

Chapter 13 - Building a Better Window (Introducing Windows Forms)

Chapter 14 - A Better Painting Framework (GDI+)

To illustrate the while loop, here is a brief look at C# file manipulation (which is fully detailed in Chapter 16).

Chapter 15 - Programming with Windows Forms Controls

The StreamReader class, defined within the System.IO namespace, encapsulates the details of reading

Chapter 16 - The System.IO Namespace

from a given file. Notice that you are obtaining an instance of the StreamReader type as a return value from

Chapter 17 - Data Access with ADO.NET

the static File.OpenText() method. Once you have opened the boot.ini file, you are able to iterate over each

Part Five - Web Applications and XML Web Services

line in the file using StreamReader.ReadLine():

Chapter 18 - ASP.NET Web Pages and Web Controls

Chapter 19

- ASP.NET Web Applications

try

// Just in case we can't find the correct file...

Chapter 20

- XML Web Services

{

 

Index

// Open the file named 'boot.ini'.

List of Figures

StreamReader strReader = File.OpenText("C:\\boot.ini");

List of Tables

// Read the next line and dump to the console.

string strLine;

while(null != (strLine = strReader.ReadLine()))

{

Console.WriteLine(strLine);

}

// Close the file.

strReader.Close();

}

catch(FileNotFoundException e)

{

Console.WriteLine(e.Message);

}

Closely related to the while loop is the do/while statement. Like a simple while loop, do/while is used when

C# and the .NET Platform, Second Edition

you need to perform some action for an undetermined number of times. The difference is that do/while

by Andrew Troelsen ISBN:1590590554

loops are guaranteed to execute the corresponding block of code at least once (in contrast, it is possible

Apress © 2003 (1200 pages)

that a simple while loop may never execute if the terminating condition is false from the onset).

This comprehensive text starts with a brief overview of the

C# language and then quickly moves to key technical and

// The do/while statement

architectural issues for .NET developers.

string ans;

do

Table{ of Contents

Console.Write("Are you done? [yes] [no] : ");

C# and the .NET Platform, Second Edition

ans = Console.ReadLine();

Introduction

}while(ans != "yes");

Part One - Introducing C# and the .NET Platform

Chapter 1 - The Philosophy of .NET

Chapter 2 - Building C# Applications

Part Two - The C# Programming Language

SOURCE The Iterations project is located under the Chapter 3 subdirectory.

Chapter 3 - C# Language Fundamentals

CODE

Chapter 4 - Object-Oriented Programming with C#

Chapter 5 - Exceptions and Object Lifetime

Chapter 6 - Interfaces and Collections

Chapter 7 - Callback Interfaces, Delegates, and Events

Chapter 8 - Advanced C# Type Construction Techniques

Part Three - Programming with .NET Assemblies

Chapter 9 - Understanding .NET Assemblies

Chapter 10 - Processes, AppDomains, Contexts, and Threads

Chapter 11 - Type Reflection, Late Binding, and Attribute-Based Programming

Part Four - Leveraging the .NET Libraries

Chapter 12 - Object Serialization and the .NET Remoting Layer

Chapter 13 - Building a Better Window (Introducing Windows Forms)

Chapter 14 - A Better Painting Framework (GDI+)

Chapter 15 - Programming with Windows Forms Controls

Chapter 16 - The System.IO Namespace

Chapter 17 - Data Access with ADO.NET

Part Five - Web Applications and XML Web Services

Chapter 18 - ASP.NET Web Pages and Web Controls

Chapter 19 - ASP.NET Web Applications

Chapter 20 - XML Web Services

Index

List of Figures

List of Tables

C# ControlC#Flowand theConstructs.NET Platform, Second Edition

by Andrew Troelsen

ISBN:1590590554

Now that you can iterate over a block of code, the next related concept is how to control the flow of program

Apress © 2003 (1200 pages)

execution. C# defines two simple constructs to alter the flow of your program, based on various contingencies.

This comprehensive text starts with a brief overview of the

you have our goodC#friend,languagetheand"if/else"th nstatementquickly moves. Unliketo keyC andtechnicalC++ however,and the if/else statement only operate Boolean expressionsarchitectural(not ad-hocissuesvaluesfor .NETsuchdevelopersas -1, 0 and. so on). Given this, if/else statements typically involve use of the following C# operators (Table 3-5).

Table of Contents

 

 

 

 

 

Table 3-5: C# Relational and Equality Operators

 

 

C# and the .NET Platform, Second Edition

 

 

 

 

 

Example

 

Meaning in Life

IntroductionC# Equality/Relational

 

 

PartOperatorOne - Introducing C# and the .NET Platform

 

Usage

 

 

 

 

 

 

 

 

 

 

 

Chapter 1

- The Philosophy of .NET

 

if(age = = 30)

 

Returns true only if each expression is the

 

= =

 

 

 

 

Chapter 2

- Building C# Applications

 

 

 

same.

Part Two - The C# Programming Language

 

 

Chapter!= 3

- C# Language Fundamentals

 

if("Foo" !=

 

Chapter 4

- Object-Oriented Programming with

myStr)

 

C#

 

 

 

 

 

Chapter 5

- Exceptions and Object Lifetime

 

if(bonus < 2000)

 

<

 

 

 

Chapter 6

- Interfaces and Collections

 

if(bonus > 2000)

 

 

 

>

 

 

 

Chapter 7

- Callback Interfaces, Delegates, and

Events

 

 

 

 

Chapter 8

- Advanced C# Type Construction Techniques

<=

 

 

if(bonus <=

Part Three - Programming with .NET Assemblies2000)

Returns true only if each expression is different.

Returns true if expression A is less than, greater than, less

than or equal to, or greater

Chapter 9 - Understanding .NET Assemblies

>= if(bonus >= than or equal to expression B.

Chapter 10 - Processes, AppDomains, Contexts, and Threads

2000)

Chapter 11 - Type Reflection, Late Binding, and Attribute-Based Programming

Part Four - Leveraging the .NET Libraries

C and C++ programmers need to be aware that the old tricks of testing a condition for a value "not equal to zer

Chapter 12 - Object Serialization and the .NET Remoting Layer

will not work in C#. Let's say you want to see if the string you are working with is greater than zero. You may be

Chapter 13 - Building a Better Window (Introducing Windows Forms) tempted to write:

Chapter 14 - A Better Painting Framework (GDI+)

Chapter 15 - Programming with Windows Forms Controls

// This is illegal, given that Length returns an int, not a bool.

Chapter 16 - The System.IO Namespace

string thoughtOfTheDay = "You CAN teach an old dog new tricks";

Chapter 17 - Data Access with ADO.NET

// Error!

if(thoughtOfTheDay.Length)

Part Five - Web Applications and XML Web Services

{

Chapter 18 - ASP.NET Web Pages and Web Controls

// Stuff...

Chapter 19 - ASP.NET Web Applications

}

Chapter 20 - XML Web Services

Index

List of Figures

ListIf youf Tableswish to make use of the String.Length property to determine if you have an empty string, you need to mo your conditional expression as follows:

// No problem.

// Better! This resolves to {true | false}.

if(0!= thoughtOfTheDay.Length)

{

 

// Stuff...

 

}

 

An "if" statement may be composed of complex expressions as well. As you would expect, if conditionals can containelse statements to perform more complex testing. The syntax is identical to C(++) and Java (and not too removed from Visual Basic). To build such a beast, C# offers an expected set of conditional operators (Table 3

Table 3-6: C# Conditional Operators

C# ConditionalC# andOperatorthe .NET Platform,ExampleSecond Edition

by Andrew Troelsen

ISBN:1590590554

&&

if((age = = 30) && (name = = "Fred"))

Apress © 2003 (1200 pages)

||This comprehensive textif((agestarts=with= 30)a brief|| (nameov rview= = "Fred"))of the C# language and then quickly moves to key technical and

!

architectural issues forif(!myBool).NET developers.

Meaning in Life

Conditional AND operator

Conditional OR operator Conditional NOT operator

The other simple selection construct offered by C# is the switch statement. As I am sure you are aware, switch Tablestatementsof Contentsallow you to handle program flow based on a predefined set of choices. For example, the following

C#applicationand the .NETpromptsPla form,the userSecondforEditionone of three possible values. Based on the user input, act accordingly:

Introduction

Part One - Introducing C# and the .NET Platform

// The good ol' switch statement.

Chapter 1 - The Philosophy of .NET

class Selections

Chapter 2 - Building C# Applications

{

Part Twopublic- The C#staticProgrammintg LanguageMain(string[] args)

Chapter {3 - C# Language Fundamentals

Chapter 4 - ObjectConsole-Ori nted.WriteLine("WelcomeProgramming with C# to the world of .NET");

Chapter 5 - ExceptionsConsoleand.WriteLine("1Obj ct Lif time = C#\n2 = Managed C++ (MC++)\n3 = VB.NET\n");

Console.Write("Please select your implementation language:");

Chapter 6 - Interfaces and Collections

string s = Console.ReadLine();

Chapter 7 - Callback Interfaces, Delegates, and Events

int n = int.Parse(s);

Chapter 8 - Advanced C# Type Construction Techniques

Part Three - Programming with .NET Assemblies

switch(n)

Chapter 9 - Understanding .NET Assemblies

{

Chapter 10 - Processes, AppDomains, Contexts, and Threads

// C# demands that each case (including 'default') which

Chapter 11 - Type Reflection, Late Binding, and Attribute-Based Programming

// contains executable statements, must have

Part Four - Leveraging the .NET Libraries

// a terminating 'break' or 'goto' to avoid fall through.

Chapter 12 - Object Serialization and the .NET Remoting Layer case 1:

Chapter 13 - Building a Better Window (Introducing Windows Forms)

Console.WriteLine("Good choice! C# is all about managed code.

Chapter 14 - A Better Painting Framework (GDI+)

 

break;

Chapter 15 - Programming with Windows Forms Controls

 

case 2:

Chapter 16 - The System.IO Namespace

 

Console.WriteLine("Let me guess, maintaining a legacy system?

Chapter 17 - Data Access with ADO.NET

 

break;

Part Five - Web Applications and XML Web Services

 

case 3:

Chapter 18 - ASP.NET Web Pages and Web Controls

 

Console.WriteLine("VB .NET: It is not just for kids anymore..

Chapter 19 - ASP.NET Web Applications

 

break;

Chapter 20 - XML Webdefault:S rvices

Index

Console.WriteLine("Well...good luck with that!");

List of Figures

break;

List of Tables

}

}

return 0;

 

}

 

Note It is worth pointing out that the C# also supports switching on character data as well (it even supports "null" case for empty strings).

SOURCE The Selections project is located under the Chapter 3 subdirectory.

CODE

The CompleteC# andSettheof.NETC#Platform,OperatorsSec nd Edition

by Andrew Troelsen

ISBN:1590590554

C# defines a number of operators in addition to those you have previously examined. By and large, these

Apress © 2003 (1200 pages)

operators behave like their C(++) and Java counterparts. Table 3-7 lists the set of C# operators in order of

This comprehensive text starts with a brief overview of the precedence. C# language and then quickly moves to key technical and

architectural issues for .NET developers.

Table 3-7: The Full Set of C# Operators

 

 

 

 

 

 

 

 

 

TableOperatorof ContentsCategory

 

Operators

 

 

 

 

 

 

C# and the .NET Platform, Second Edition

 

+ - ! ~ ++x x++ --x x--

 

 

 

 

Unary

 

 

 

 

 

Introduction

 

 

 

 

 

 

 

 

 

 

 

PartMultiplicativeOne - Introducing C# and the .NET

Platform* / %

 

 

 

 

 

 

 

 

 

 

Chapter 1

- The Philosophy of .NET

 

+ -

 

 

 

 

Additive

 

 

 

 

 

 

 

Chapter 2

- Building C# Applications

 

 

 

 

 

 

 

 

 

PartShiftTwo - The C# Programming Language

 

<< >>

 

 

 

 

 

 

 

 

 

 

Chapter 3

- C# Language Fundamentals

 

< > <= >= is as

 

 

 

 

Relational

 

 

 

 

 

 

Chapter 4

- Object-Oriented Programming

 

with C#

 

 

 

 

 

 

 

ChapterEquality5

- Exceptions and Object Lifetime

 

= = !=

 

 

 

 

 

 

 

 

 

Chapter 6

- Interfaces and Collections

 

&

 

 

 

 

Logical AND

 

 

 

 

 

 

Chapter 7

- Callback Interfaces, Delegates,

 

and Events

 

 

 

 

 

 

 

ChapterLogical8 XOR- Advanced C# Type Construction

^ Techniques

 

 

 

 

 

 

Part Three - Programming with .NET Assemblies

 

 

 

 

Logical OR

 

|

 

 

Chapter 9

- Understanding .NET Assemblies

 

 

 

 

 

 

 

 

 

 

ChapterConditional10 - Processes,AND

AppDomains, Contexts,&& and Threads

 

 

 

 

 

 

 

 

 

 

Chapter 11

- Type Reflection, Late Binding,

 

and Attribute-Based Programming

 

 

 

 

Conditional OR

 

 

||

 

Part Four - Leveraging the .NET Libraries

 

 

 

 

 

 

ChapterConditional12 - Object Serialization and the

.NET?: Remoting Layer

 

 

 

 

 

 

 

 

 

 

Chapter 13

- Building a Better Window

(Introducing Windows Forms)

 

 

 

 

Indirection / Address

 

* -> &

 

 

 

 

Chapter 14

- A Better Painting Framework

 

(GDI+)

 

 

 

 

 

 

 

ChapterAssignment15 - Programming with Windows

 

Forms= *= /=Controls%= += -= <<= >>= &= ^= |=

 

 

 

 

 

 

 

 

 

 

Chapter 16

- The System.IO Namespace

 

 

 

The only operators that you may not be familiar with are the is and as operators. The is operator is used to

Chapter 17 - Data Access with ADO.NET

verify at runtime if an object is compatible with a given type. One common use for this operator is to

Part Five - Web Applications and XML Web Services

determine if a given object supports a particular interface, as you discover in Chapter 6. The as operator

Chapter 18 - ASP.NET Web Pages and Web Controls

allows you to downcast between types (seen briefly in this chapter and formally in Chapter 4) or

Chapter 19 - ASP.NET Web Applications

implemented interface.

Chapter 20 - XML Web Services

Index

Also note that the C# language does support the use of classic C(++) pointer manipulations, via the *, ->

List of Figures

and & operators. If you choose to make use of these operators, you are bypassing the runtime memory Listmanagementof Tables scheme and writing code in "unsafe mode." You learn about these operators in Chapter 8.

As for the remaining operators, I will make the assumption that many (if not all) of them are old hat to you. If you need additional information regarding the C# looping and decision constructs, consult the C# Language Reference using MSDN.

Соседние файлы в предмете Программирование