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

protection error

I have a structure like this :
public struct index_struct
{
static char [] IP = new char [16] ;
int port;
static char [] FileN = new char [50];
int ID;
int Bnum;
long m_DataSize;
int Version;
}
then i have an array of this struct:

public index_struct [] indecies ;

then in one of the methods of same class in whic previous are defined i
try to do the following:

int id = indecies[j].ID;
but get an error : "'trial_v1.ListenForBroadcast.index_struct.ID' is
inaccessible due to its protection level
"

Can someone explain the situation?

thanks..

Nov 15 '05 #1
4 1356
Lee Chapman wrote:
You're a C++ programmer at heart, aren't you? :-) yes...
In C#, the default member accessibility for structs is 'private', not
'public'. You need to put the 'public' keyword in front of all those member
variables to make them accessible from outside the struct.
thanks for the solution... On a side note, that structure looks rather large to be a C# struct; I
suspect you'd be much better off making it a class. In C# only use structs
when you *need* a value-type.
i tried to make it class , but now i got another problem.
i my code i assign size of my struct (now class) to some variable :
int i = sizeof(index_struct);

and now it gives error like :
ListenForBroadcast.cs(124): Cannot take the address or size of a
variable of a managed type ('trial_v1.ListenForBroadcast.index_struct')


- Lee

"Rustam Asgarov" <ru****@boun.edu.tr> wrote in message
news:uZ**************@TK2MSFTNGP10.phx.gbl...
I have a structure like this :
public struct index_struct
{
static char [] IP = new char [16] ;
int port;
static char [] FileN = new char [50];
int ID;
int Bnum;
long m_DataSize;
int Version;
}
then i have an array of this struct:

public index_struct [] indecies ;

then in one of the methods of same class in whic previous are defined i
try to do the following:

int id = indecies[j].ID;
but get an error : "'trial_v1.ListenForBroadcast.index_struct.ID' is
inaccessible due to its protection level
"

Can someone explain the situation?

thanks..



Nov 15 '05 #2
On a side note, that structure looks rather large to be a C# struct; I
suspect you'd be much better off making it a class. In C# only use structs when you *need* a value-type.


i tried to make it class , but now i got another problem.
i my code i assign size of my struct (now class) to some variable :
int i = sizeof(index_struct);

and now it gives error like :
ListenForBroadcast.cs(124): Cannot take the address or size of a
variable of a managed type ('trial_v1.ListenForBroadcast.index_struct')


Why do you need the size of the struct?

- Lee
Nov 15 '05 #3
bacause i am doing something like this:
indexsize=(n_bytes_received - 4*sizeof(int))/sizeof(index_struct);
indecies = new index_struct [indexsize] ;

Lee Chapman wrote:
On a side note, that structure looks rather large to be a C# struct; I
suspect you'd be much better off making it a class. In C# only use
structs
when you *need* a value-type.


i tried to make it class , but now i got another problem.
i my code i assign size of my struct (now class) to some variable :
int i = sizeof(index_struct);

and now it gives error like :
ListenForBroadcast.cs(124): Cannot take the address or size of a
variable of a managed type ('trial_v1.ListenForBroadcast.index_struct')

Why do you need the size of the struct?

- Lee


Nov 15 '05 #4

"Rustam Asgarov" <ru****@boun.edu.tr> wrote in message
news:ux*************@TK2MSFTNGP11.phx.gbl...
bacause i am doing something like this:
indexsize=(n_bytes_received - 4*sizeof(int))/sizeof(index_struct);
indecies = new index_struct [indexsize] ;

Hmmm. Well I'm going to leave you to it; although I suspect serialization
might cover what you're trying to do - your C# looks so much like C++ that I
suspect you're not getting the most out of the CLR.

- Lee
Nov 15 '05 #5

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

Similar topics

9
by: Howard | last post by:
I am currently looking at the various packages that are available for software protection. I have a particular question that I'd welcome your feedback on. Background info: I work for a company...
0
by: SoftComplete Development | last post by:
SoftComplete Development Updates EXECryptor to v. 2.1.20 Software piracy! Cracked serial numbers! Thousands of commercial products are posted on the warez sites and become available to all who...
1
by: Larry | last post by:
I have a VB background and am developing a new windows app in Csharp. I'm getting the error. 'inaccessible due to its protection level' I've added a TextBox1 and a Button1 to a form. I...
1
by: Ken.r | last post by:
I'm working my way throught ASP Resource Kit tutorial lab 3. This following code was working in the HTML page: private void btnSignIn_Click(object sender, System.EventArgs e) { // Add user...
1
by: Arjen | last post by:
Hi, I have this inside a webusercontrol: private string MenuItem = new string; Inside the .ascx file I do this: <%= MenuItem(0) %> And I get this error: ....is inaccessible due to its...
3
by: xenophon | last post by:
This following innocuous code: System.IO.DirectoryInfo fff = new System.IO.DirectoryInfo(); System.IO.FileInfo ppp = fff.GetFiles( Request.MapPath(".") ); for( int ccc=0 ; ccc < ppp.Length ;...
1
by: musosdev | last post by:
Hi I've got a project I've just run through the conversion wizard, and it's giving me a few headaches. I've got a user control which has controls referrenced from its calling page...
37
by: dmoran21 | last post by:
I am a mathematician trying to write a program in C to do some curve fitting. When I get to the point where I attempt to enter data in my arrays, I get a General Protection Exception error message....
0
by: KhoaNguyen | last post by:
Hi, When i compiled these two source files, it gives me an error saying: Inaccesssible Due to its protection level. ------------Base Class----------------- using System; using...
0
by: dba | last post by:
Hi folks, I would just like to share with you SQL CodeSecure, a newly released database protection and auditing tool from SqlLabs: SQL CodeSecure provides ultimate protection from unauthorized...
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
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?
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
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
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.