473,387 Members | 1,575 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.

Tranferring parameters to structs in a class?

ORC
How to transfer a parameter to a structure in a class?

In a class (MySubClass) I have defined a private structure (I don't want it
to be public) and a property {get; set} like this

private TestStruct
{
public int member_1;
public int member_2;
}

TestStruct TS = new TestStruct();

public TestStruct members
{
get
{
return TS;
}
set
{
TS = value;
}
}

In another class (MyParentClass) Doing this:

MySubClass tc = new MySubClass();
testVariable = tc.members.member_1;

works very well ! But doing this:

tc.members.member_1 = testVariable;

Doesn't work - the compiler raises an error saying:
"Cannot modify the return value of
'Application_for_tests.TestClass.variables' because it is not a variable"

So how is the correct way to do stuff like that?

Thanks
Ole
Nov 16 '05 #1
1 1138
ORC,

You would have to declare your structure as a class. If you do this:

tc.members.member_1 = testVariable;

Then the return value of members is a copy of the TS field that is
stored in the class instance. You will be modifying the field on the copy,
and not on the instance held by the class.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"ORC" <or*@sol.dk> wrote in message
news:eN**************@TK2MSFTNGP15.phx.gbl...
How to transfer a parameter to a structure in a class?

In a class (MySubClass) I have defined a private structure (I don't want
it
to be public) and a property {get; set} like this

private TestStruct
{
public int member_1;
public int member_2;
}

TestStruct TS = new TestStruct();

public TestStruct members
{
get
{
return TS;
}
set
{
TS = value;
}
}

In another class (MyParentClass) Doing this:

MySubClass tc = new MySubClass();
testVariable = tc.members.member_1;

works very well ! But doing this:

tc.members.member_1 = testVariable;

Doesn't work - the compiler raises an error saying:
"Cannot modify the return value of
'Application_for_tests.TestClass.variables' because it is not a variable"

So how is the correct way to do stuff like that?

Thanks
Ole

Nov 16 '05 #2

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

Similar topics

8
by: Rick | last post by:
Hi, We all know that Java has classes but how about basic storage objects like structs? C and C++ have Structs, Pascal has Records, Visual Basic has Types etc. How about Java? Greetings, Rick
16
by: Michi Henning | last post by:
Below is a bit of code that creates a delegate. The delegate invokes a member function of a struct. The code compiles, but has surprising behavior: using System; namespace ConsoleApplication1...
5
by: Bilgehan.Balban | last post by:
Hi, I am currently brushing up my c++ knowledge and I would like to ask you about the differences between classes and C structs, in the function/method perspective. 1) Is it correct to say...
15
by: Marcus | last post by:
I created a VB.Net 1.1 application that iterates through all the tables in any basic Access 2000 database passed to it and generates the same table structure in a SQL Server Express database. The...
61
by: Marty | last post by:
I am new to C# and to structs so this could be easy or just not possible. I have a struct defined called Branch If I use Branch myBranch = new Branch(i); // everything works If I use Branch...
29
by: Dom | last post by:
I'm really confused by the difference between a Struct and a Class? Sometimes, I want just a group of fields to go together. A Class without methods seems wrong, in that it carries too much...
43
by: JohnQ | last post by:
Are a default constructor, destructor, copy constructor and assignment operator generated by the compiler for a struct if they are not explicitely defined? I think the answer is yes, because...
5
by: leon | last post by:
Hello group, Somebody has a example where web methods receive and send classes in the parameters. I looking the best way to send parameters to web service and anybody told me something like...
5
by: =?Utf-8?B?RGF2aWQgTGV2aW5l?= | last post by:
This is really more of a "why was C# designed this way?" type of question. Hope this is the write forum for this question. Given the following : class Base1 { public int i; } struct Base2...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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.