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

how can i do in C# safe code

I have problem how can i do it in C# safe code.

class ABase
{
SetValueFromXX(string name,source,dest) // in C++ ( string name,source,
int *dest)
{
1. step
in source i find row with name

2. step
set value from source on finded row to dest, // in c++ *dest =
source.value
How can i do in safe c# - i need put value to property in class A
???
}
}

class A : ABase
{
int aa;
int ab;
int ac;

// and many next property

public int Count = 3;
B b=new B(Count);
b[0] = new B( "power" , here need reference to aa); // in C++ &aa;
b[1] = new B( "volt" , here need reference to ab); // &ab
b[2] = new B( "aper", here need reference to ac); // &ac

ReadData()
{
1. step
read Data from something .... to source object

2. step
set data from source to property over base class ABase

for(i=0;i<Count;i++)
SetValueFromXX(b[i].mName, source ,b[i].mS_A_R);
// this don't work and it is problem in c#. When i use ref
i can put data only in class B
// i need put data to property aa,ab,ac in this class.
}
}

class B
{
B(string name, ??? S_A_R) // in c++ (string name,int *refer);
{
mName = name;
mS_A_R = S_A_R; // in c++ mS_A_R = refer;
}
public string mName;
public something about reference ??? mS_A_R; // in c++ int
*mS_A_R;
}

Can you help me ???
thanks Jankis.
email : ho*****@hotmail.com
Jul 19 '05 #1
4 2704
Jankis,

Things declared as class types will be passed by reference.
Things declared as struct types, or primitives like int, will be passed by
value. If you need these to pass by reference use the keyword ref, e.g.
void fnX(ref int y) { }.

Brendan

"Jankis" <ho*****@hotmail.com> wrote in message
news:Ol**************@tk2msftngp13.phx.gbl...
I have problem how can i do it in C# safe code.

class ABase
{
SetValueFromXX(string name,source,dest) // in C++ ( string name,source,
int *dest)
{
1. step
in source i find row with name

2. step
set value from source on finded row to dest, // in c++ *dest = source.value
How can i do in safe c# - i need put value to property in class A
???
}
}

class A : ABase
{
int aa;
int ab;
int ac;

// and many next property

public int Count = 3;
B b=new B(Count);
b[0] = new B( "power" , here need reference to aa); // in C++ &aa;
b[1] = new B( "volt" , here need reference to ab); // &ab
b[2] = new B( "aper", here need reference to ac); // &ac

ReadData()
{
1. step
read Data from something .... to source object

2. step
set data from source to property over base class ABase

for(i=0;i<Count;i++)
SetValueFromXX(b[i].mName, source ,b[i].mS_A_R);
// this don't work and it is problem in c#. When i use ref i can put data only in class B
// i need put data to property aa,ab,ac in this class.
}
}

class B
{
B(string name, ??? S_A_R) // in c++ (string name,int *refer);
{
mName = name;
mS_A_R = S_A_R; // in c++ mS_A_R = refer;
}
public string mName;
public something about reference ??? mS_A_R; // in c++ int
*mS_A_R;
}

Can you help me ???
thanks Jankis.
email : ho*****@hotmail.com

Jul 19 '05 #2
Brendan Duffy <br*****@dotnetsolutions.com.au> wrote:
Things declared as class types will be passed by reference.


No they won't. References will be passed by value, which is a different
thing.

See http://www.pobox.com/~skeet/csharp/parameters.html

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Jul 19 '05 #3
Hi.
Thanks your answer bad, standard reference isn't way.
I need reference over next class.

class ABase
{
SetValue(object dest)
{
dest = 10;
}
}

class A : ABase
{
int a;
B b = new B(ref a);

SetValue(b); // in this method i need set property a
// this way set only property mdest in class B
}

class B
{
int mdest;
B(ref int dest)
{
mdest = dest;
}
}

down is complete sample why i need ref over class.
class ABase
{
SetValueFromXX(string name,source,dest) // in C++ ( string name,source,
int *dest)
{
1. step
in source i find row with name

2. step
set value from source on finded row to dest, // in c++ *dest =
source.value
How can i do in safe c# - i need put value to property in class A
???
}
}

class A : ABase
{
int aa;
int ab;
int ac;

// and many next property
// Realy Count is About 100

public int Count = 3;
B b=new B(Count);
b[0] = new B( "power" , here need reference to aa); // in C++ &aa;
b[1] = new B( "volt" , here need reference to ab); // &ab
b[2] = new B( "aper", here need reference to ac); // &ac

ReadData()
{
1. step
read Data from something .... to source object

2. step
set data from source to property over base class ABase

for(i=0;i<Count;i++)
SetValueFromXX(b[i].mName, source ,b[i].mS_A_R);
// this don't work and it is problem in c#. When i use ref
i can put data only in class B
// i need put data to property aa,ab,ac in this class.
}
}

class B
{
B(string name, ??? S_A_R) // in c++ (string name,int *refer);
{
mName = name;
mS_A_R = S_A_R; // in c++ mS_A_R = refer;
}
public string mName;
public something about reference ??? mS_A_R; // in c++ int
*mS_A_R;
}


"Jon Skeet" <sk***@pobox.com> wrote in message
news:MP************************@news.microsoft.com ...
Brendan Duffy <br*****@dotnetsolutions.com.au> wrote:
Things declared as class types will be passed by reference.


No they won't. References will be passed by value, which is a different
thing.

See http://www.pobox.com/~skeet/csharp/parameters.html

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too

Jul 19 '05 #4
[Please see my sig - don't reply to me by mail and on the newsgroups at
the same time. It only causes confusion.]

Jankis <ho*****@hotmail.com> wrote:
Thanks your answer bad, standard reference isn't way.
Pardon? I don't understand.
I need reference over next class.


<snip>

Basically you're not going to manage that. Once you've returned from a
method or constructor, any value type is effectively immutable - you
can't change it at a later date from elsewhere.

If you want that kind of behaviour, you'll need some kind of wrapper,
so you pass a reference to the wrapper to the B constructor, and then
you can modify the contents of the object referred to by that reference
at a later date.

To be honest though, that doesn't sound like a very clean way of coding
it - I'm not sure I understand (in human terms) what you're really
trying to do. I suspect you'd be better off using a map of some
description though.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Jul 19 '05 #5

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

Similar topics

42
by: Irmen de Jong | last post by:
Pickle and marshal are not safe. They can do harmful things if fed maliciously constructed data. That is a pity, because marshal is fast. I need a fast and safe (secure) marshaler. Is xdrlib the...
9
by: Jody Gelowitz | last post by:
I am trying to find the definition of "Safe Printing" and cannot find out exactly what this entitles. The reason is that I am trying to print contents from a single textbox to no avail using the...
9
by: Andy Chang | last post by:
Hi, If I have this function void DoSomething(int& index) { ::Sleep(10000); DoSomethingWith(index); } Is the variable index thread safe? Meaning that if I call this from two
2
by: Jeff Chan | last post by:
I have read the documentation from msdn to try to understanding the concept of "Type safe". Would someone give me an example of code segment illustrating what is *Non* type safe? Many Thanks,...
0
by: gm | last post by:
Immediately after generating the Access application from the Source Safe project I get: "-2147467259 Could not use ''; file already in use." If Access database closed and then reopened I get:...
15
by: Laser Lu | last post by:
I was often noted by Thread Safety declarations when I was reading .NET Framework Class Library documents in MSDN. The declaration is usually described as 'Any public static (Shared in Visual...
1
by: jecheney | last post by:
Hi, Im currently using the following code for reading/writing to a network socket. private StreamReader clientStreamReader; private StreamWriter clientStreamWriter; .... TcpClient tcpClient...
4
by: George2 | last post by:
Hello everyone, Here is Bjarne's exception safe sample, http://www.research.att.com/~bs/3rd_safe.pdf template <class Tclass Safe {
7
by: bvdp | last post by:
I'm finding my quest for a safe eval() quite frustrating :) Any comments on this: Just forget about getting python to do this and, instead, grab my set of values (from a user supplied text file)...
3
by: =?Utf-8?B?anBhdHJjaWs=?= | last post by:
Don't see any official notice that compiled library dll's loaded in the BIN directory of an asp.net website need to be thread safe, but concurrent visits to the same web site sure bear this out....
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
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
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...
0
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...

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.