473,326 Members | 2,126 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,326 software developers and data experts.

how to specifically new object in global namespace?

Please check the code below. If I new a object in Main() as "genClass<xxx>",
it will create the class namespace1.genClass<>. So how to create the
genClass<> in the global in Main()?

using System;
class genClass<T>
{
private T _t;
public T T1
{
get { return _t; }
set { _t = value; }
}
public void echo()
{
Console.WriteLine("class genClass<T>");
}
}

namespace namespace1
{
class genClass<T>
{
private T _t;
public T T1
{
get { return _t; }
set { _t = value; }
}
public void echo()
{
Console.WriteLine("generic2.genClass<T>");
}
}

class Program
{
static void Main(string[] args)
{
genClass<int> g = new genClass<int>();
g.T1 = 111;
g.echo();
}
}
}

Nov 17 '05 #1
4 1085
Why would you want to place a class outside of a namespace? It is
strongly recommended that you always use a namespace for any class as
this organizes your classes and makes them easier to document and use
in references.

Best Regards
Johann Blake

Nov 17 '05 #2
noname <no****@discussions.microsoft.com> wrote:
Please check the code below. If I new a object in Main() as "genClass<xxx>",
it will create the class namespace1.genClass<>. So how to create the
genClass<> in the global in Main()?


Change Main to:

static void Main(string[] args)
{
global::genClass<int> g = new global::genClass<int>();
g.T1 = 111;
g.echo();
}

Or, my preferred suggestions:

1) Don't create types without namespaces
2) Try very hard to avoid giving two types the same name

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #3
Got it. Thanks a lot.

"Jon Skeet [C# MVP]" wrote:
noname <no****@discussions.microsoft.com> wrote:
Please check the code below. If I new a object in Main() as "genClass<xxx>",
it will create the class namespace1.genClass<>. So how to create the
genClass<> in the global in Main()?


Change Main to:

static void Main(string[] args)
{
global::genClass<int> g = new global::genClass<int>();
g.T1 = 111;
g.echo();
}

Or, my preferred suggestions:

1) Don't create types without namespaces
2) Try very hard to avoid giving two types the same name

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 17 '05 #4
Got it. Thanks a lot.

"Jon Skeet [C# MVP]" wrote:
noname <no****@discussions.microsoft.com> wrote:
Please check the code below. If I new a object in Main() as "genClass<xxx>",
it will create the class namespace1.genClass<>. So how to create the
genClass<> in the global in Main()?


Change Main to:

static void Main(string[] args)
{
global::genClass<int> g = new global::genClass<int>();
g.T1 = 111;
g.echo();
}

Or, my preferred suggestions:

1) Don't create types without namespaces
2) Try very hard to avoid giving two types the same name

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 17 '05 #5

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

Similar topics

1
by: Gregg Altschul | last post by:
I have a Shared Object which its sole purpose is to create objects of a certain type and return a pointer to the object to the user. Therefore, the user becomes the owner of this object and is...
2
by: Tony Johansson | last post by:
Hello! I'm reading a book about C++ and there is something that I don't understand so I ask you. Below I have the text from the book and the code from the file where main is located and some...
15
by: randyr | last post by:
I am developing an asp.net app based on a previous asp application. in the asp applications global.asa file I had several <object id="id" runat="server" scope="scope" class="comclass"> tags for...
3
by: Adam | last post by:
We have a web site that uses .vb for the web pages and .cs for a class module. We are getting the error in .NET 2.0 and VS 2005 beta 2. It does work with .NET 1.1. When trying to access a page...
12
by: Andrew Poulos | last post by:
With the following code I can't understand why this.num keeps incrementing each time I create a new instance of Foo. For each instance I'm expecting this.num to alert as 1 but keeps incrementing. ...
44
by: petermichaux | last post by:
Hi, I have been using the following line of code to create an object called "Serious" if it doesn't already exist. if (Serious == null) {var Serious = {};} This works in the scripts I use...
1
by: Bryan Parkoff | last post by:
An object can be defined using a class. The class contains variables and functions. It has a pointer to bind variables and functions. If I want to create more than one object. The class can...
6
by: Rajesh | last post by:
I read Global Object's constructor will be called before main() function; In which situation it can be really helpful? Is it good practice use Global object and its constructor ? Thanks,...
2
by: Immortal_Nephi | last post by:
Sometimes, programmers decide to create only one object. One object is used for a whole program. You can run two or more programs at the same time. Each program has a copy of its own object....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.