473,513 Members | 2,513 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2709
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
2541
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
4084
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
5596
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
1885
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
7698
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
2739
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
4592
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
1906
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
242
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
1512
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
7161
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
7539
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
5686
agi2029
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,...
1
5089
isladogs
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...
0
4746
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...
0
3234
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3222
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1596
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.