Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 31st, 2009, 06:50 PM
Registered User
 
Join Date: May 2008
Posts: 7
Thanks: 1
Thanked 0 Times in 0 Posts
Default Chapter 9 p. 314: How to import a namespace?

Try it out Step 3 concerning "Sending mail from the ContactForm User Control" says: "Open the Code Behind of the ContactForm.ascx user control and import the following namespace at the top of the file."

The illustration for C# shows "using System.Net.Mail;"

How in the world does one do that?

The book's index has two entries concerning importing, citing pps. 27 and 173. I read pages 27 and 173 and am still not sure how one imports the namespace. Is simply typing "using System.Mail;" all there is to it?
 
Old January 31st, 2009, 07:58 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Featheriver,

Yes, that's exactly what you need todo: type the following at the top of the file, near the other using statements:

Code:
using System.Net.Mail;
In order to use a type like the MailMessage class you typically need to do two things:

1. Create a project reference to the DLL that contains the type so your project can see the types defined in that DLL.

2. Bring the type "in scope" by adding a using statement.

The first is already done as the DLL that contains the MailMessage class is added by default. The reason you need to explicitly add a using statement has a few reasons:

1. First, it avoids clutter in the IntelliSense list. Imagine you didn't have to include a using statement and instead would see all types defined in all referenced DLLs. You would see hundreds or even thousands of items, making it hard to find the one you need

2. Secondly, it avoids type collisions. The book mentions the System.Web.UI.Page and the Microsoft.Word.Page classes as an example. Both are called Page. Which one would you be referring to if both of them were in scope automatically? By adding a using statement, you explicitly tell the compiler from which namespace you want to use a specific type.

Does this help? It's a bit long answer for something as "yes, add the using statement", but I hope it helps in clarifying why you need all this....

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Import Namespace seannie ASP.NET 2.0 Basics 0 December 7th, 2006 04:48 AM
Can't import a namespace w/vbc command line oneillj ASP.NET 1.0 and 1.1 Basics 0 June 14th, 2006 08:05 PM
Error import namespace sersanoi Classic ASP Databases 0 August 18th, 2005 12:10 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.