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

Access Modifier in structs - help!

Hi there,

I had seen examples for classes, but i had no idea how to implement the same
thing in struct. I am quite mix up!

Which one is correct?

Scenario:
WForm.cs - the one that calls FileA.cs to access the structures
FileA.cs - contains all structures

1)

public struct TestA
{
public byte a;
public byte b;

public struct TestB
{
public byte c;
public byte d;
}
}

yes/no - but i think this is not recommended, i read it somewhere.. not
secure or something

2)

public struct TestA
{
internal byte a;
internal byte b;

public struct TestB
{
internal byte c;
internal byte d;
}
}

yes/no?

3)

public struct TestA
{
internal byte a;
internal byte b;

internal struct TestB
{
internal byte c;
internal byte d;
}
}

yes/no

4)

internal struct TestA
{
public byte a;
public byte b;

public struct TestB
{
public byte c;
public byte d;
}
}

yes/no

5)

internal struct TestA
{
public byte a;
public byte b;

internal struct TestB
{
public byte c;
public byte d;
}
}

yes/no

6)

public struct TestA
{
private byte a;
private byte b;

public struct TestB
{
private byte c;
private byte d;
}
}

yes/no - but how could this is possible? Is there a way to get out the
private values

7)

public struct TestA
{
private byte a;
private byte b;

private struct TestB
{
private byte c;
private byte d;
}
}

yes/no

8)

private struct TestA
{
public byte a;
public byte b;

private struct TestB
{
public byte c;
public byte d;
}
}

yes/no

Any idea please? Can anyone clear my doubts? Thanks.
--
Regards,
Chua Wen Ching :)
Nov 16 '05 #1
3 1862
OK the key thing is are WForm.cs and FileA.cs going to be built into the same assembly or into two separate ones?

Same assembly:
1) best avoided as you have no control over what values are put into the byte member - no validation. But other than that it will work fine.
2) this will be exactly the same as 1) except code in other assemblies will not be able touch the byte members
3) this will be the same as 2) except code in other assemblies will not be able to touch TestB
4) same as 1) except code in other assemblies will not be able to touch TestA
5) same as 1) except code in other assemblies will not be able to touch TestA or TestB
6) TestA and TestB will be accessible to code in other assemblies but the byte members can only be touched by code in their declaring struct. This is normally dealt with by having public properties to access the fields. This gives the benefit of being able to validate values written to the byte members
7) You cannot make a type (class or struct) private - only public and internal are allowed
8) same as 7)

You missed out the option of:
internal struct TestA
{
private byte a;
private byte b;
}

internal struct TestB
{
private byte c;
private byte d;
}
This gives maximum protection - only code in the assembly can get to the structs and you control access to the state (you would need to add public properties to access the state).

Different assemblies:
1) best avoided as you have no control over what values are put into the byte member - no validation. But other than that it will work fine.
2) this will be exactly the same as 1) except code in other assemblies will not be able touch the byte members so you will have to provide public properties
3) this will not work as the form will not be able to get to TestB
4) this will not work as the form will not be able to get to TestA
5) this will not work as the form will not be able to get to TestA or TestB
6) TestA and TestB will be accessible to code in other assemblies so it will work fine. But the byte members can only be touched by code in their declaring struct. This is normally dealt with by having public properties to access the fields. This gives the benefit of being able to validate values written to the byte members
7) You cannot make a type (class or struct) private - only public and internal are allowed
8) same as 7)
?
Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/
Hi there,

I had seen examples for classes, but i had no idea how to implement the same thing in struct. I am quite mix up!

Which one is correct?

Scenario:
WForm.cs - the one that calls FileA.cs to access the structures FileA.cs - contains all structures

1)

public struct TestA
{
public byte a;
public byte b;

public struct TestB
{
public byte c;
public byte d;
}
}

yes/no - but i think this is not recommended, i read it somewhere.. not secure or something

2)

public struct TestA
{
internal byte a;
internal byte b;

public struct TestB
{
internal byte c;
internal byte d;
}
}

yes/no?

3)

public struct TestA
{
internal byte a;
internal byte b;

internal struct TestB
{
internal byte c;
internal byte d;
}
}

yes/no

4)

internal struct TestA
{
public byte a;
public byte b;

public struct TestB
{
public byte c;
public byte d;
}
}

yes/no

5)

internal struct TestA
{
public byte a;
public byte b;

internal struct TestB
{
public byte c;
public byte d;
}
}

yes/no

6)

public struct TestA
{
private byte a;
private byte b;

public struct TestB
{
private byte c;
private byte d;
}
}

yes/no - but how could this is possible? Is there a way to get out the private values

7)

public struct TestA
{
private byte a;
private byte b;

private struct TestB
{
private byte c;
private byte d;
}
}

yes/no

8)

private struct TestA
{
public byte a;
public byte b;

private struct TestB
{
public byte c;
public byte d;
}
}

yes/no

Any idea please? Can anyone clear my doubts? Thanks.
--
Regards,
Chua Wen Ching :)

---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.760 / Virus Database: 509 - Release Date: 10/09/2004

[microsoft.public.dotnet.languages.csharp]

Nov 16 '05 #2
Hi Richard,

Thanks for the tips. It will be useful for me.

But i had 1 question,

can i break

from:
-----
struct A
{
struct B
{

}
}
to:
---
struct A
{

}
struct B
{

}

// if this is the case, how does struct A and B relates to each other?

Thanks!

:)

"Richard Blewett [DevelopMentor]" wrote:
OK the key thing is are WForm.cs and FileA.cs going to be built into the same assembly or into two separate ones?

Same assembly:
1) best avoided as you have no control over what values are put into the byte member - no validation. But other than that it will work fine.
2) this will be exactly the same as 1) except code in other assemblies will not be able touch the byte members
3) this will be the same as 2) except code in other assemblies will not be able to touch TestB
4) same as 1) except code in other assemblies will not be able to touch TestA
5) same as 1) except code in other assemblies will not be able to touch TestA or TestB
6) TestA and TestB will be accessible to code in other assemblies but the byte members can only be touched by code in their declaring struct. This is normally dealt with by having public properties to access the fields. This gives the benefit of being able to validate values written to the byte members
7) You cannot make a type (class or struct) private - only public and internal are allowed
8) same as 7)

You missed out the option of:
internal struct TestA
{
private byte a;
private byte b;
}

internal struct TestB
{
private byte c;
private byte d;
}
This gives maximum protection - only code in the assembly can get to the structs and you control access to the state (you would need to add public properties to access the state).

Different assemblies:
1) best avoided as you have no control over what values are put into the byte member - no validation. But other than that it will work fine.
2) this will be exactly the same as 1) except code in other assemblies will not be able touch the byte members so you will have to provide public properties
3) this will not work as the form will not be able to get to TestB
4) this will not work as the form will not be able to get to TestA
5) this will not work as the form will not be able to get to TestA or TestB
6) TestA and TestB will be accessible to code in other assemblies so it will work fine. But the byte members can only be touched by code in their declaring struct. This is normally dealt with by having public properties to access the fields. This gives the benefit of being able to validate values written to the byte members
7) You cannot make a type (class or struct) private - only public and internal are allowed
8) same as 7)
?
Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/
Hi there,

I had seen examples for classes, but i had no idea how to implement the same thing in struct. I am quite mix up!

Which one is correct?

Scenario:
WForm.cs - the one that calls FileA.cs to access the structures FileA.cs - contains all structures

1)

public struct TestA
{
public byte a;
public byte b;

public struct TestB
{
public byte c;
public byte d;
}
}

yes/no - but i think this is not recommended, i read it somewhere.. not secure or something

2)

public struct TestA
{
internal byte a;
internal byte b;

public struct TestB
{
internal byte c;
internal byte d;
}
}

yes/no?

3)

public struct TestA
{
internal byte a;
internal byte b;

internal struct TestB
{
internal byte c;
internal byte d;
}
}

yes/no

4)

internal struct TestA
{
public byte a;
public byte b;

public struct TestB
{
public byte c;
public byte d;
}
}

yes/no

5)

internal struct TestA
{
public byte a;
public byte b;

internal struct TestB
{
public byte c;
public byte d;
}
}

yes/no

6)

public struct TestA
{
private byte a;
private byte b;

public struct TestB
{
private byte c;
private byte d;
}
}

yes/no - but how could this is possible? Is there a way to get out the private values

7)

public struct TestA
{
private byte a;
private byte b;

private struct TestB
{
private byte c;
private byte d;
}
}

yes/no

8)

private struct TestA
{
public byte a;
public byte b;

private struct TestB
{
public byte c;
public byte d;
}
}

yes/no

Any idea please? Can anyone clear my doubts? Thanks.
--
Regards,
Chua Wen Ching :)

---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.760 / Virus Database: 509 - Release Date: 10/09/2004

[microsoft.public.dotnet.languages.csharp]

Nov 16 '05 #3
Well sure you can change from one to the other but the meaning of the code changes:

struct A
{
struct B
{
}
}

In this case you are saying that B is part of the implementation, or fundamentally associated with A - in such a way that B makes no sense without A.

struct A
{
}
struct B
{
}

In this case (assuming they are declared in the same assembly) then you are saying these structs are related by being part of the same component or deployment and may be related on that basis, but no more than that.

I'm assuming the lack of access modifiers is not significant ( if it were, in the first example B would not be visible outside of A)

Regards

Richard Blewett - DevelopMentor
Http://staff.develop.com/richardb/weblog

?
nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/
Hi Richard,

Thanks for the tips. It will be useful for me.

But i had 1 question,

can i break

from:
-----
struct A
{
struct B
{

}
}
to:
---
struct A
{

}
struct B
{

}

// if this is the case, how does struct A and B relates to each other?

Thanks!

:)
Nov 16 '05 #4

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

Similar topics

2
by: Dan Disney | last post by:
I have read conflicting information on the access scope of VB.Net class declarations when no access modifier is specified. MSDN library documentation states "Classes that do not specify an access...
3
by: N Khan via .NET 247 | last post by:
Hi, I know the usage of access modifier ?public? in DLL assembliesbut I am a bit puzzled that if let say I have a public class inan exe assembly then what purpose access modifier ?public?...
1
by: Jacob N. Rohde | last post by:
Hi guys, I was under the assumption that the default type access modifier for classes/structs is internal. But the MCAD Study Guide (from MS even) says public?!?! (The Dr. GUI .NET tutorial from...
1
by: Ashkan Daie | last post by:
Hi All, Is there an internal access modifier in managed vc++ like vc#? Thanks, Ashkan
1
by: Mark Kamoski | last post by:
Hi-- Please help. What is the default access modifier value for a Sub or a Function when one has not explicitly been set. In MSDN, in "Access Types", it states... "If no access modifier...
3
by: Mr Newbie | last post by:
I am messing around with Web User Controls at present and (think) I have discovered the following. 1.) The identifier for the control in the code behind must match the ID for the control on the...
5
by: dost | last post by:
can u tell me the diffrence between...... private public and protected .........in........these.......which one...is access modifier....and which one..is specifier....... and....the diffrence...
9
by: JT | last post by:
Here is the overall structure I will be referring to: End-program ProvideWorkFlow.dll Forms and methods that properly manipulate calls to methods in AccessUtils AccessUtils (a web service)...
5
by: wpmccormick | last post by:
What is the cleanest way to gain access to object methods and properties across classes and files in the same namespace? Example: A form object frmForm in file frmForm.cs creates obj1 defined in...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
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: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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.