473,671 Members | 2,446 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,des t) // 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 2720
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*****@hotmai l.com> wrote in message
news:Ol******** ******@tk2msftn gp13.phx.gbl...
I have problem how can i do it in C# safe code.

class ABase
{
SetValueFromXX( string name,source,des t) // 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*****@dotnet solutions.com.a u> 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.co m>
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,des t) // 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.co m> wrote in message
news:MP******** *************** *@news.microsof t.com...
Brendan Duffy <br*****@dotnet solutions.com.a u> 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.co m>
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*****@hotmai l.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.co m>
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
2586
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 only option? I would expect that it is fast and safe because it (the xdr spec) has been around for so long. Or are there better options (perhaps 3rd party libraries)?
9
4102
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 PrintDialog control under a security setting with only SafePrinting allowed. I have attached a sample project that I am using to try to accomplish this. The print dialog appears, but when I press the Print button, I get an exception (at the end...
9
5613
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
1896
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, Jeff.
0
7711
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: "-2147467259 The database has been place in a state by user 'Admin' on machine ..... that prevents it from being opened or locked."
15
2767
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 Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.' So, does this mean All the static/shared methods written in .NET compatible programming language, such as C#, VB.NET, are guaranteed to be...
1
4617
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 = new TcpClient(server_host_name, server_port);
4
1917
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) and call an external program like 'bc' to do the dirty work. I think that this would avoid someone from embedding os.system("rm ...") in what I thought would be a math expression and having it maybe do damage? Perhaps I'm getting too paranoid in...
3
1521
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. Does anyone know the answer to this?
0
8401
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8926
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8824
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8673
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6236
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5703
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4227
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2060
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.