PC Review


Reply
Thread Tools Rate Thread

how can i do in C# safe code

 
 
Jankis
Guest
Posts: n/a
 
      23rd Jul 2003
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 : (E-Mail Removed)


 
Reply With Quote
 
 
 
 
Brendan Duffy
Guest
Posts: n/a
 
      25th Jul 2003
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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 : (E-Mail Removed)
>
>



 
Reply With Quote
 
Jon Skeet
Guest
Posts: n/a
 
      25th Jul 2003
Brendan Duffy <(E-Mail Removed)> 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 - <(E-Mail Removed)>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
 
Reply With Quote
 
Jon Skeet
Guest
Posts: n/a
 
      25th Jul 2003
[Please see my sig - don't reply to me by mail and on the newsgroups at
the same time. It only causes confusion.]

Jankis <(E-Mail Removed)> 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 - <(E-Mail Removed)>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
 
Reply With Quote
 
Jankis
Guest
Posts: n/a
 
      25th Jul 2003
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Brendan Duffy <(E-Mail Removed)> 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 - <(E-Mail Removed)>
> http://www.pobox.com/~skeet/
> If replying to the group, please do not mail me too



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Newbie: How safe is source code? John Microsoft ASP .NET 5 2nd Apr 2010 11:40 AM
Keeping the code behind files safe Tamer Ibrahim Microsoft ASP .NET 1 17th Apr 2009 06:29 PM
Needlessly Safe Code Verde Microsoft C# .NET 15 28th Apr 2008 09:53 PM
Memory address in safe code caldera Microsoft C# .NET 1 25th Aug 2004 08:45 AM
how can i do it in C# safe code. Jankis Microsoft C# .NET 3 24th Jul 2003 10:37 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:01 PM.