我怎么能用C#安全代码 [英] how can i do in C# safe code

查看:62
本文介绍了我怎么能用C#安全代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有问题怎么用C#安全代码呢。


class ABase

{

SetValueFromXX(string name,source,dest)//在C ++中(字符串名称,来源,

int * dest)

{

1. step

在源代码中我找到了一个名字的行


2.步骤

从源代码行到dest的设置值,//在c ++中* dest =

source.value

我怎样才能在安全的c#中做 - 我需要把价值放在A级的财产中

???

}

}


A类:ABase

{

int aa;

int ab;

int ac;


//以及许多下一个属性


public int Count = 3;

B b = new B(Count);

b [0] = new B(power,这里需要参考aa); //在C ++& aa;

b [1] =新B(伏特,这里需要参考ab); //& ab

b [2] =新B(aper,这里需要参考ac); //& ac


ReadData()

{

1.步骤

读取数据从某些东西......到源对象


2.步骤

在基类ABase上设置从源到属性的数据


for(i = 0; i< Count; i ++)

SetValueFromXX(b [i] .mName,source,b [i] .mS_A_R);

//这不起作用,这是c#中的问题。当我使用ref

i只能将数据放在B类中

//我需要将数据放入此类中的属性aa,ab,ac。

}

}


B级

{

B(字符串名称,?? ?S_A_R)// in c ++(string name,int * refer);

{

mName = name;

mS_A_R = S_A_R; //在c ++中mS_A_R =引用;

}

公共字符串mName;

公开引用的内容??? mS_A_R; //在c ++ int

* mS_A_R;

}


你能帮我吗???

谢谢Jankis。

电子邮件: ho*****@hotmail.com

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

推荐答案

Jankis,


声明为类类型的东西将通过引用传递。

声明为struct类型的东西,或者像int这样的原语,将通过

值传递。如果你需要这些通过引用传递使用关键字ref,例如

void fnX(ref int y){}。


Brendan


" Jankis" <豪***** @ hotmail.com>在留言中写道

新闻:Ol ************** @ tk2msftngp13.phx.gbl ...
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...
我有问题怎么能我用C#安全代码来实现。

类ABase
{SetValueFromXX(string name,source,dest)//用C ++编写(字符串名称,来源,
int * dest)
1.步骤
在源代码中我找到了一行名称

2.步骤
设置值从源头到有序行到dest,// in c ++ * dest
= source.value
我怎么能在安全的c#中做 - 我需要把价值放在A级的财产上
???
}
}

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

//和许多下一个属性

public int Count = 3;
B b = new B(Count);
b [0] = new B(power,这里需要参考aa); //在C ++& aa;
b [1] =新B(伏特,这里需要参考ab); //& ab
b [2] =新B(aper,这里需要参考ac); //& ac

ReadData()
{
1.步骤
读取数据......来源对象
2.步骤
通过基类ABase将数据从源设置为属性

for(i = 0; i< Count; i ++)
SetValueFromXX(b [i] .mName ,source,b [i] .mS_A_R);
//这不起作用,这在c#中是个问题。当我使用
ref时,我只能将数据放在B类中
//我需要将数据放入此类中的属性aa,ab,ac。
}
} B类
{B(字符串名称,??? S_A_R)//在c ++中(字符串名称,int *引用);
{
mName =名称;
mS_A_R = S_A_R; //在c ++中mS_A_R =引用;
}
公共字符串mName;
有关引用的公开信息??? mS_A_R; //在c ++ int
* mS_A_R;
}

你能帮帮我吗???
谢谢Jankis。
电子邮件: ho ***** @ hotmail.com
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



Brendan Duffy< br ***** @ dotnetsolutions.com.au>写道:
Brendan Duffy <br*****@dotnetsolutions.com.au> wrote:
声明为类类型的东西将通过引用传递。
Things declared as class types will be passed by reference.




不,他们不会。引用将通过值传递,这是一个不同的
事物。


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


-

Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet/

如果回复小组,请不要给我发邮件。 />



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


嗨。

谢谢你的回答不好,标准参考不是。

我需要参考下一堂课。


class ABase

{

SetValue(object dest)

{

dest = 10;

}

}


A类:ABase

{

int a;

B b = new B(ref a);


SetValue(b); //在这个方法中我需要设置属性a

//这样在B类中只设置属性m

}


B级

{

int mdest;

B(ref int dest)

{

mdest = dest;

}

}


down是完整示例为什么我需要参考课程。

class ABase

{

SetValueFromXX(string name,source,dest)//在C ++中(字符串名称,来源,

int * dest)

{

1.步骤

来源我发现名字行


2.步骤

从finded行的源到dest的设置值,//在c ++ * dest =

source.value

我怎么能在安全的c#中做 - 我需要把价值放在A级的房产上

???

}

}


A级:ABase

{

int aa;

int ab;

int ac;


//和许多下一个属性

// Realy Count大约100


p ublic int Count = 3;

B b = new B(Count);

b [0] = new B(power) ,这里需要参考aa); //在C ++& aa;

b [1] =新B(伏特,这里需要参考ab); //& ab

b [2] =新B(aper,这里需要参考ac); //& ac


ReadData()

{

1.步骤

读取数据从某些东西......到源对象


2.步骤

在基类ABase上设置从源到属性的数据


for(i = 0; i< Count; i ++)

SetValueFromXX(b [i] .mName,source,b [i] .mS_A_R);

//这不起作用,这是c#中的问题。当我使用ref

i只能将数据放在B类中

//我需要将数据放入此类中的属性aa,ab,ac。

}

}


B级

{

B(字符串名称,?? ?S_A_R)// in c ++(string name,int * refer);

{

mName = name;

mS_A_R = S_A_R; //在c ++中mS_A_R =引用;

}

公共字符串mName;

公开引用的内容??? mS_A_R; // in c ++ int

* mS_A_R;

}


" Jon Skeet" < SK *** @ pobox.com>在消息中写道

新闻:MP ************************ @ news.microsoft.com ...
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>写道:
Brendan Duffy <br*****@dotnetsolutions.com.au> wrote:
声明为类类型的东西将通过引用传递。
Things declared as class types will be passed by reference.



不,他们不会。引用将通过值传递,这是一个不同的事情。

请参阅 http://www.pobox.com/~skeet/csharp/parameters.html

-
Jon Skeet - < sk *** @ pobox.com>
http:// www .pobox.com / ~subet /
如果回复小组,请不要给我发邮件



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



这篇关于我怎么能用C#安全代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆