473,388 Members | 1,468 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

using directive and namespaces

Hello-

I am a little confused about something. I have create a .cs file that looks
like this:
using System;
namespace MyApp.Types
{
using INT = System.Int32;
}

In my Main() function, even though I have added the using sirective : using
Types; I get compiler errors with this line of code:
INT nrBones = 0;
So this doesn't make sense to me. How do you have custom types all over
your application if you can't do it like this? What am I missing?

Thanks for any help,
Steve
Nov 15 '05 #1
3 1613
So this doesn't make sense to me.
It does to me. :-) The using alias syntax only affects the source file
it's in, not your entire project.

How do you have custom types all over
your application if you can't do it like this? What am I missing?


Copy the using statement to all source files you need it. Or define
your own struct called INT with implicit conversion opererators
to/from int. Or just avoid creating type aliases.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 15 '05 #2
I figured that was the case, but I couldn't believe it.
I need to use a ton of C structs that use types like DWORD, _WORD, INT and I
that that I could just add a bunch of using statements to map things around.
Nope! ;)

Thanks for the quick response, I will just cram it all into one file,
ugly... but this is a ont-time-use tool, so who cares ;)
"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:ux**************@TK2MSFTNGP10.phx.gbl...
So this doesn't make sense to me.


It does to me. :-) The using alias syntax only affects the source file
it's in, not your entire project.

How do you have custom types all over
your application if you can't do it like this? What am I missing?


Copy the using statement to all source files you need it. Or define
your own struct called INT with implicit conversion opererators
to/from int. Or just avoid creating type aliases.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Nov 15 '05 #3
"neverstill" <sk************@yahoo.com> wrote in message
news:ej**************@TK2MSFTNGP09.phx.gbl...
Hello-

I am a little confused about something. I have create a .cs file
that looks like this:

using System;
namespace MyApp.Types
{
using INT = System.Int32;
}

In my Main() function, even though I have added the using
directive : using Types; I get compiler errors with this line
of code: INT nrBones = 0;

So this doesn't make sense to me. How do you have custom
types all over your application if you can't do it like this?
What am I missing?


You haven't created a custom type, merely an alias [i.e. alternate or
shortened name] for an existing type. I'm assuming, also, that this is what
you actually wish to do - post again with additional information if it
isn't.

The reason the 'aliasing' didn't work was because you created it [I'm
assuming this, since you didn't show all your code] in one scope but
attempted to use it in another.

The following code snippets should helps clear this up. As they show, you
just need to ensure the alias created by the using directive is done so in
the correct scope / namespace.

I hope this helps.

Anthony Borla

// FILE: Example1.cs
using System;

using INT = System.Int32;

public class X
{
INT returnINT() { INT x = 5; return x; }

public static void Main(String[] args)
{
INT x = new X().returnINT();
Console.WriteLine(x);
}
}

// FILE: Example2.cs
using System;

namespace MyApp
{
using INT = System.Int32;

public class X
{
INT returnINT() { INT x = 5; return x; }

public static void Main(String[] args)
{
INT x = new X().returnINT();
Console.WriteLine(x);
}
}
}

Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: beliavsky | last post by:
Many of my C++ programs have the line using namespace std; but the "Accelerated C++" book of Koenig and Moo has many examples where the library names are included one at a time, for example ...
12
by: Calum Grant | last post by:
In older C++ computer books, you'll often see using namespace std; even in my 1996 copy of Stroustrup. Nowadays, it seems to be considered better to qualify names to make it clearer what...
3
by: Imre | last post by:
As far as I know, the using directive is transitive, and I'm not sure I like this. So I'd like to ask if there's any workaround. Consider this: namespace MyNameSpace { void...
4
by: clintonG | last post by:
When using Visual Studio.NET I observe adding a new Web Form may have default References added such as... References o- System o- System.Data o- System.Drawing o- System.Web o- System.XML
3
by: xzzy | last post by:
I was wondering why we have to have using System.Data using System.Configuration using etc.... why are they not all lumped into one 'using'? In other words, is there a best way to use...
30
by: Pep | last post by:
Is it best to include the code "using namespace std;" in the source or should each keyword in the std namespace be qualified by the namespace tag, such as std::cout << "using std namespace" <<...
11
by: subramanian100in | last post by:
Suppose the following is in Test.h #ifndef TEST_H #define TEST_H #include <iostream> #include <string> using namespace std;
8
by: =?Utf-8?B?Q2hyaXMgSGFsY3Jvdw==?= | last post by:
Hi there I've successfully added some .NET validation controls to a page (using <asp:RequiredFieldValidator ...), however when I try to set the 'display' property to 'dynamic', my page then...
3
by: =?Utf-8?B?QUEyZTcyRQ==?= | last post by:
With using System.Configuration why is ConfigurationManager.AppSettings generate an error? Why does the error resolve itself when, in addition to the using directive, I add a reference...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.