Wrox Programmer Forums
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB 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 October 3rd, 2010, 07:58 PM
Registered User
Join Date: Jun 2010
Posts: 9
Thanks: 2
Thanked 0 Times in 0 Posts
Smile Namespaces

Hello people..
I have small question about namespaces.
In chapter 5(the chapter that focuses on c# coding basics) we created class calculator, which exposes 4 simple methods.
This class was created inside the Calculator.cs file, which in turn was stored in the App_Code folder.
Then in the CalculatorDemo.aspx page, we created an instance of the above class, and called it's methods.
My question is that: We could create an instance of the Calculator class, just with the name of the class-that is Calculator, without having to prefix it with the fully qualified name of the namespace that includes the Calculator class.
Inside CalculatorDemo.aspx, I have commented out all of the using statements in the page, and I could still create an instance of Calculator, with no errors, including full support of the VS2010's intellisense.
I kept on reading the namespace section of chapter 5, and after reading it, i dont get it, how can I use the Calculator class only by it's name, when all of the using statements are commented out.
I guess that CalculatorDemo.aspx and Calculator.cs are both under the same namespace, is that right? and what namespcae is it? I've tried ctrl+dot and got nothing?

10x for any reply...
Old October 4th, 2010, 02:40 AM
Imar's Avatar
Wrox Author
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts

Hi there,

I guess that CalculatorDemo.aspx and Calculator.cs are both under the same namespace, is that right? and what namespcae is it?
Yes, that's correct. They aren't in an addressable namepsace, but in a global, unnamed namespace. Since both the Web Form and the Calculator are in this same global namespace, they can see each other. Things will break as you'd expect if you move the calculator to its own namespace and don't add a using statement to the code behind of the web form.


Imar Spaanjaars
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!
The Following User Says Thank You to Imar For This Useful Post:
lustigon (October 4th, 2010)

Similar Threads
Thread Thread Starter Forum Replies Last Post
Namespaces and DLLs Akobold C# 0 March 18th, 2007 08:08 PM
Namespaces Amateur BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 November 27th, 2006 05:19 PM
namespaces anchal C# 1 July 3rd, 2006 02:53 PM
XML Namespaces billy_bob_the_3rd XML 1 January 31st, 2005 03:41 PM
NAMESPACES - WHAT ARE THEY? p_nut33 C# 2 July 31st, 2003 03:18 AM

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