Hi, i want to access an array of objects inside a method like this
using System;
using System.Collecti ons.Generic;
namespace ObjectArray
{
class MainClass{
class MyClass
{
public int x=0;
MyClassTo[] obj=new MyClassTo[2];
public MyClass(){
obj[0]=new MyClassTo();
obj[1]=new MyClassTo();
}
public void display(){
show(this);
}
}
class MyClassTo{
int x;
int y;
}
public static void show(MyClass my){ // Error here
obj[0].x=10; //How do i access the
object array?
}
public static void Main(string[] args){
Console.ReadLin e();
}
}
}
but i get an error "Inconsiste nt accessibility: parameter type
'ObjectArray.Ma inClass.MyClass ' is less accessible than method
'ObjectArray.Ma inClass.show(Ob jectArray.MainC lass.MyClass)' (CS0051) - "
What am i doing wrong? 8 1252
Since the show method is public, all parameters to that method have to
be accessible. The MyClass class is private, which is why you get the
error. Change the MyClass class to public, and it will work.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"azz131" <bi********@ntl world.comwrote in message
news:1l******** *********@newsf e1-win.ntli.net...
Hi, i want to access an array of objects inside a method like this
using System;
using System.Collecti ons.Generic;
namespace ObjectArray
{
class MainClass{
class MyClass
{
public int x=0;
MyClassTo[] obj=new MyClassTo[2];
public MyClass(){
obj[0]=new MyClassTo();
obj[1]=new MyClassTo();
}
public void display(){
show(this);
}
}
class MyClassTo{
int x;
int y;
}
public static void show(MyClass my){ // Error here
obj[0].x=10; //How do i access the
object array?
}
public static void Main(string[] args){
Console.ReadLin e();
}
}
}
but i get an error "Inconsiste nt accessibility: parameter type
'ObjectArray.Ma inClass.MyClass ' is less accessible than method
'ObjectArray.Ma inClass.show(Ob jectArray.MainC lass.MyClass)' (CS0051) - "
What am i doing wrong?
azz131 <bi********@ntl world.comwrote:
<snip>
but i get an error "Inconsiste nt accessibility: parameter type
'ObjectArray.Ma inClass.MyClass ' is less accessible than method
'ObjectArray.Ma inClass.show(Ob jectArray.MainC lass.MyClass)' (CS0051) - "
What am i doing wrong?
You're trying to use MyClass - which is only accessible to other types
within the same assembly - as a parameter to the show method, which is
public (i.e. available to all types, regardless of assembly).
Either make the show method internal, or make MyClass public.
Oh, and you'll need to add some way of accessing the array within
MyClass, as otherwise MyClassTo doesn't have any way of getting to the
data.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
On Thu, 10 May 2007 11:17:33 -0700, azz131 <bi********@ntl world.comwrote:
[...]
but i get an error "Inconsiste nt accessibility: parameter type
'ObjectArray.Ma inClass.MyClass ' is less accessible than method
'ObjectArray.Ma inClass.show(Ob jectArray.MainC lass.MyClass)' (CS0051) - "
What am i doing wrong?
The compiler is telling you that the access modifiers for the two things
don't match. In particular, your class is not public, but the method is.
That means even though your method is visible to callers outside of the
class, the type used in the parameter list is not. Since it's not nice to
publish a method to callers but keep the type of the parameter to that
method secret, the compiler complains. :)
Pete
MyClass is not private, but rather internal.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c omwrote in
message news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
Since the show method is public, all parameters to that method have to
be accessible. The MyClass class is private, which is why you get the
error. Change the MyClass class to public, and it will work.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"azz131" <bi********@ntl world.comwrote in message
news:1l******** *********@newsf e1-win.ntli.net...
>Hi, i want to access an array of objects inside a method like this
using System; using System.Collecti ons.Generic;
namespace ObjectArray {
class MainClass{ class MyClass { public int x=0; MyClassTo[] obj=new MyClassTo[2];
public MyClass(){ obj[0]=new MyClassTo(); obj[1]=new MyClassTo(); } public void display(){ show(this); } }
class MyClassTo{ int x; int y; }
public static void show(MyClass my){ // Error here obj[0].x=10; //How do i access the object array?
} public static void Main(string[] args){ Console.ReadLin e(); } } } but i get an error "Inconsiste nt accessibility: parameter type 'ObjectArray.M ainClass.MyClas s' is less accessible than method 'ObjectArray.M ainClass.show(O bjectArray.Main Class.MyClass)' (CS0051) - " What am i doing wrong?
azz131 wrote:
Hi, i want to access an array of objects inside a method like this
using System;
using System.Collecti ons.Generic;
namespace ObjectArray
{
class MainClass{
class MyClass
{
public int x=0;
MyClassTo[] obj=new MyClassTo[2];
If you want to access the member from outside the class, it can't be
private.
public MyClassTo[] obj = new MyClassTo[2];
However, you should consider keeping all member variables private, and
create properties for exposing them outside the class.
>
public MyClass(){
obj[0]=new MyClassTo();
obj[1]=new MyClassTo();
}
public void display(){
show(this);
}
}
class MyClassTo{
int x;
int y;
public int x;
public int y;
}
public static void show(MyClass my){ // Error here
obj[0].x=10; //How do i access the
object array?
my.obj[0].x = 10;
>
}
public static void Main(string[] args){
Console.ReadLin e();
}
}
}
but i get an error "Inconsiste nt accessibility: parameter type
'ObjectArray.Ma inClass.MyClass ' is less accessible than method
'ObjectArray.Ma inClass.show(Ob jectArray.MainC lass.MyClass)' (CS0051) - "
What am i doing wrong?
You have made the show method public, but the class MyClass is private.
That means that the method is visible outside the class, but it can't be
used outside the class as it's impossible to create a value for the
parameter.
--
Göran Andersson
_____ http://www.guffa.com
Nicholas Paldino [.NET/C# MVP] wrote:
MyClass is not private, but rather internal.
The default accessibility for class members is private, and as MyClass
is a member of MainClass that would make it private, wouldn't it?
I prefer to always specify the accessibility level, so that there never
is any doubt what it is. :)
--
Göran Andersson
_____ http://www.guffa.com
Nicholas Paldino [.NET/C# MVP] <mv*@spam.guard .caspershouse.c omwrote:
MyClass is not private, but rather internal.
You were right first time, actually - I hadn't noticed before, but it's
nested inside MainClass, so it's private by default.
To the OP: Why do you have all these nested classes? They should crop
up pretty rarely in most code.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Göran Andersson <gu***@guffa.co mwrote:
Nicholas Paldino [.NET/C# MVP] wrote:
MyClass is not private, but rather internal.
The default accessibility for class members is private, and as MyClass
is a member of MainClass that would make it private, wouldn't it?
I prefer to always specify the accessibility level, so that there never
is any doubt what it is. :)
On the other hand, you should generally make things as private as you
can get away with, which is what the default is. I like the fact that
by specifying an access modifier, I'm saying "I want this to be more
public than it would be by default."
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Dave Williams |
last post by:
First off...total noob to VB. So far have learned a lot in 1.5 days and
feel fairly comfortable at throwing screens up. However, I want to start
writing forms that revolve around an access database.
From what I have read to date it looks like VB can only display 1 record at
a time. I suspect this is not the case. How easy is it to display 10
records at a time (in a table format) that can be scrolled up and down ?
When the current...
|
by: Matt Hollingsworth |
last post by:
Hello,
Very new to python, so a noob question. When I've written stuff in
JavaScript or MEL in the past, I've always adopted the variable naming
convention of using a $ as the first character (no, I don't use perl,
never have). Not possible in python. What are some good options that
people commonly use so that they can easily and quickly identify
variable with just a glance? When I was writing stuff in SoftImage
XSI/JScript, many of...
|
by: davestrike |
last post by:
I am a noob to sql and asp programming. I am working on a db for the
gaming squad I am a member of. One of the pages I created is a roster
list of all the squad members. Part of this roster is listing each
member's email address. What several people have asked of me is to
make it so the email addresses can be clicked on to open their email
programs, just as html allows the mailto function to work.
Here is a copy of the coding I am...
|
by: We need more power captain |
last post by:
Hi,
I know less than a noob, I've been asked to do some compiles in VC++ 6
without knowing too much at all. (I'm a COBOL program normally so
this is all too much for me)
I open VC++6, open the workspace and then:
Build>Batch Build
|
by: mike_wilson1333 |
last post by:
I would like to generate every unique combination of numbers 1-5 in a 5
digit number and follow each combo with a newline. So i'm looking at
generating combinations such as: (12345) , (12235), (55554) and so on.
What would be the best way to do this? So, basically i'm looking for a
list of all combinations of 1-5 in a 5 digit unique number. Also, when
I send the list to print there can't be any duplicates of the combos.
Thanks,
| |
by: davetelling |
last post by:
I am not a programmer, I'm an engineer trying to make an interface to a
product I'm designing. I have used C# to make a form that interrogates the
unit via the serial port and receives the data. I want to be able to draw
lines in a picturebox based upon certain data points I have received. I
dragged a picturebox from the toolbar onto my form, but after having gone
through the help files, looking online and trying a variety of things, I...
|
by: Lang Murphy |
last post by:
I'm baaaaack... some of you answered a question I had last week. Only
problem is: I'm a dope who doesn't understand most of what y'all posted. Raw
noob when it comes to .Net and C#.
So I'm going to be more specific... All I need to do at the moment is figure
out how to replace our usage of .ini files as configuration files for our
small, utility type apps. I'm not looking to use XML as a data stream or
anything like that. Not right now,...
|
by: cypherzero |
last post by:
Using this header file (mstring.h) for a class defined in a seperate file (mstring.cpp) I recieve 8 'unresolved external symbol' errors when trying to use the class in my main source file (main.cpp). Could someone please tell me if I am making yet another newbie mistake? I'm sure this has always worked in the past!
///////////////
// mstring.h //
///////////////
#include <string>
class MSTRING : public std::string
{
|
by: Carnell, James E |
last post by:
I am thinking about purchasing a book, but wanted to make sure I could
get through the code that implements what the book is about (Artificial
Intelligence a Modern Approach). Anyway, I'm not a very good programmer
and OOP is still sinking in, so please don't answer my questions like I
really know anything.
MY QUESTION:
What is a slot? In class Object below the __init__ has a slot. Note:
The slot makes use of a data object called...
|
by: SCRIPT KEEPER |
last post by:
Hello,
I am a complete noob and just starting off with csharp so I apologize for my basic question. I am wanting to start powershell from inside a batch script and then to pass the powershell args from the batch, so from the batch I can use the name of the compiled csharp app without having to include the "call" command.
Something like "Compiled Csharp app.exe" "PowerShell Args" etc.....
Thank You for any help.
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |