473,386 Members | 1,804 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,386 software developers and data experts.

Problem with namespace and class

Hi,

I have the following in the project, with the following desgin.
// class 1, which is a windows form
namespace Name
{
public class aaaa
{
public int number;
.....
}
}

// class 2, which is a code file
namespace Name
{
public class bbbb
{
.....
}
}

What I am trying to do is to access the object number from class bbbb,
but it is giving me an error. Also the object was tried with
protection level as public, protected and private.
Error given: The type or namespace name 'Name' could not be found
(are you missing a using directive or an assembly reference?)
Should that work? If no, how can I share an object between the two
classes.
Thanks in Advance
Nov 16 '05 #1
5 1674
Hi,

Your object number in your class bbbb is using what type of access modifier?

Thanks.

"Drebin" wrote:
Is it a code file within the same project? That should work just as you have
it..
"Xarky" <be*********@yahoo.com> wrote in message
news:bc************************@posting.google.com ...
Hi,

I have the following in the project, with the following desgin.
// class 1, which is a windows form
namespace Name
{
public class aaaa
{
public int number;
.....
}
}

// class 2, which is a code file
namespace Name
{
public class bbbb
{
.....
}
}

What I am trying to do is to access the object number from class bbbb,
but it is giving me an error. Also the object was tried with
protection level as public, protected and private.
Error given: The type or namespace name 'Name' could not be found
(are you missing a using directive or an assembly reference?)
Should that work? If no, how can I share an object between the two
classes.
Thanks in Advance


Nov 16 '05 #2
"Chua Wen Ching" <ch************@nospam.hotmail.com> wrote in message news:<44**********************************@microso ft.com>...
Hi,

Your object number in your class bbbb is using what type of access modifier?

Thanks.
What I am doing in class bbbb, is setting the value of number=0;

"Drebin" wrote:
Is it a code file within the same project? That should work just as you have
it..
"Xarky" <be*********@yahoo.com> wrote in message
news:bc************************@posting.google.com ...
Hi,

I have the following in the project, with the following desgin.
// class 1, which is a windows form
namespace Name
{
public class aaaa
{
public int number;
.....
}
}

// class 2, which is a code file
namespace Name
{
public class bbbb
{
.....
}
}

What I am trying to do is to access the object number from class bbbb,
but it is giving me an error. Also the object was tried with
protection level as public, protected and private.
Error given: The type or namespace name 'Name' could not be found
(are you missing a using directive or an assembly reference?)
Should that work? If no, how can I share an object between the two
classes.
Thanks in Advance


Nov 16 '05 #3
Hi Xarky,

I assume:

1) I think it is under the same project

2) There are 2 class files

3) To access number in class bbbb, you need to make sure that class aaaa had
a constructor

namespace Name
{
public class aaaa
{
public aaaa() {}

public int number;
}
}

4) When you want to call the number in bbbb, this is how you do it (please
make sure it is within a method or constructor, not globally)

// correct
namespace Name
{
public class bbbb
{
public static void Main()
{
aaaa _a = new aaaa();
_a.number = 0;

// print _a.number
}
}
}

// you can't do this!
namespace Name
{
public class bbbb
{
aaaa _a = new aaaa();
_a.number = 0;
}
}

Hope it helps :)

"Xarky" wrote:
"Chua Wen Ching" <ch************@nospam.hotmail.com> wrote in message news:<44**********************************@microso ft.com>...
Hi,

Your object number in your class bbbb is using what type of access modifier?

Thanks.


What I am doing in class bbbb, is setting the value of number=0;

"Drebin" wrote:
Is it a code file within the same project? That should work just as you have
it..
"Xarky" <be*********@yahoo.com> wrote in message
news:bc************************@posting.google.com ...
> Hi,
>
> I have the following in the project, with the following desgin.
>
>
> // class 1, which is a windows form
> namespace Name
> {
> public class aaaa
> {
> public int number;
> .....
> }
> }
>
> // class 2, which is a code file
> namespace Name
> {
> public class bbbb
> {
> .....
> }
> }
>
> What I am trying to do is to access the object number from class bbbb,
> but it is giving me an error. Also the object was tried with
> protection level as public, protected and private.
> Error given: The type or namespace name 'Name' could not be found
> (are you missing a using directive or an assembly reference?)
>
>
> Should that work? If no, how can I share an object between the two
> classes.
>
>
> Thanks in Advance

Nov 16 '05 #4
Xarky <be*********@yahoo.com> wrote:
I have the following in the project, with the following desgin.


<snip>

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #5
This should be a better view of what I have.

namespace Project
{
public class Test
{
public int shared;
static void Main()
{
...
}
}
}

namespace Project
{
public class Work
{
public Work()
{
// What i was trying to do is accessing the object shared
// from here. But as it could be seen its not possible.
// Problem has now been solved by passing a copy of the
// instance shared, and having a private object within the
// class Work.
}
}
}
********* new solution as i did it now *********

namespace Project
{
public class Test
{
private int shared;
static void Main()
{
...
Work x = new Work (shared);
...
}
}
}

namespace Project
{
public class Work
{
private int personalShared;
public Work(int x)
{
this.personalShared = x;
}
}
}

Sorry for any inconvenience created.
Could you post a short but complete program which demonstrates the
problem?

Nov 16 '05 #6

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

Similar topics

18
by: George Sakkis | last post by:
I'm looking for a design to a problem I came across, which goes like this (no, it's not homework): 1. There is a (single inheritance) hierarchy of domain classes, say A<-B<-..<-Z (arrows point...
5
by: Alexis | last post by:
Hello, I have a set of classes I created from schema files using the xsd.exe tool. I'm using namespaces in the clases ( I had to because I have some classes with the same name but not the same...
1
by: wadefleming | last post by:
I have the following code which I am having trouble with. The problem is detailed in the comments near the end. Constants.cs: -------------- namespace MyApp.Const { public class Const {...
14
by: Lee Franke | last post by:
I can't seem to figure this one out. Here is my class structure namespace name { public class foo { } }
1
by: Michael | last post by:
Hello, I'm trying to implement sample I found on page templates, so I do not have to maintain "<html><head>..." on all my documents. But don't let that confuse you, this is an inheritance...
0
by: Lucas, Todd | last post by:
Hello everyone! I'm having a problem with a WebControl that I'm designing for a Menu. I've been at it for about 3 weeks now, and can't seem to get around this problem. So I'm hoping that someone...
3
by: Dan | last post by:
Hi, I have a problem using an aspx page with a Control on it. I get the following error message Compiler Error Message: CS1595: 'Test.Class2' is defined in multiple places; using definition...
10
by: anders | last post by:
I have 2 external assemblies A1 and A2 that both define class X in the global namespace. I need to use both assemblies in my VB project but the names X are ambiguous. How can I get around this...
2
by: yqlu | last post by:
I hava developed a client in C# that is connected to a 3-party XML Web Services developed in Java based on the AXIS 1.1. Most methods call are successful except for one method named "findObjects"...
5
by: michael.d.pedersen | last post by:
Hello group, I am new to Visual C++ 8 and have a seemingly trivial problem using namespaces. The scenario: I have two classes, TestClass1 and TestClass2, in the namespace Test. I would like to...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.