Static方法的变量也是staic吗? [英] Are a Static method's variables staic too?

查看:55
本文介绍了Static方法的变量也是staic吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑这是Zytan的2/27/2007主题的延续题为主题:

C#是否具有像C ++这样的静态局部变量?


在C ++中:

void mysub()

{

静态双x;

blah; blah;

}


在C ++中,变量x为后续条目保留其值为

方法


这是目标,以下是否会在C sharp中完成相同的工作?


static void mysub()

{

double x;

blah; blah;

}

-

mark b

解决方案

< blockquote> On Fri,2007年4月6日10:26:07 -0700,标记< ma ** @ discuss.microsoft.com>

写道:


[...]

在C ++中,变量x保留其后续条目的值进入

方法


这是目标,以下是否会在C

锐利中完成相同的事情?


static void mysub()

{

双x;

blah;等等;

}



不,它不会。即使在C ++中,它也不会做同样的事情。


当然,计算即使收到第一个回复所需的时间,你也可以b / b
通过尝试它已经更快地弄明白了。 :)


Pete


" Peter Duniho" < Np ********* @nnowslpianmk.com在留言中写道

news:op *************** @ petes-computer.local ...


星期五,2007年4月6日10:26:07 -0700,标记< ma ** @ discuss.microsoft.com写道:


> [...]
在C ++中,变量x保留其后续条目的值进入

那是目标,下面的C锐利会完成同样的事情吗?

静态无效mysub()
{
双x;
等等; blah;
}



不,它不会。即使在C ++中它也不会做同样的事情。



嗯...这是完全有效的C ++ ......


static void Foo()

{

static int s;

s = 5;

}


Willy。


" mark" < ma ** @ discuss.microsoft.com写信息

news:33 ************************** ******** @ microsof t.com ...


考虑这是Zytan的2/27/2007帖子的延续题为主题:

C#是否有像C ++这样的静态局部变量?"


在C ++中:

void mysub()

{

静态双x;

blah; blah;

}


在C ++中,变量x为后续条目保留其值为

方法


这是目标,以下是否会在C sharp中完成相同的工作?


static void mysub()

{

double x;

blah; blah;

}



不,它不会,而且不会,C#不支持静态本地人。 />

威利。


Consider this a continuation of 2/27/2007 thread by Zytan entitled"Subject:
Does C# have static local variables like C++?"

In C++:
void mysub()
{
static double x;
blah; blah;
}

In C++ the variable x retained its value for subsequent entries into the
method

That being the objective, will the following accomplish the same in C sharp?

static void mysub()
{
double x;
blah; blah;
}
--
mark b

解决方案

On Fri, 06 Apr 2007 10:26:07 -0700, mark <ma**@discussions.microsoft.com>
wrote:

[...]
In C++ the variable x retained its value for subsequent entries into the
method

That being the objective, will the following accomplish the same in C
sharp?

static void mysub()
{
double x;
blah; blah;
}

No, it won''t. Even in C++ it doesn''t do the same thing.

Of course, counting the time it takes to receive even the first reply, you
could have figured it out yourself faster just by trying it. :)

Pete


"Peter Duniho" <Np*********@nnowslpianmk.comwrote in message
news:op***************@petes-computer.local...

On Fri, 06 Apr 2007 10:26:07 -0700, mark <ma**@discussions.microsoft.com wrote:

>[...]
In C++ the variable x retained its value for subsequent entries into the
method

That being the objective, will the following accomplish the same in C sharp?

static void mysub()
{
double x;
blah; blah;
}


No, it won''t. Even in C++ it doesn''t do the same thing.

Hmmm... this is perfectly valid C++...

static void Foo()
{
static int s;
s = 5;
}

Willy.


"mark" <ma**@discussions.microsoft.comwrote in message
news:33**********************************@microsof t.com...

Consider this a continuation of 2/27/2007 thread by Zytan entitled"Subject:
Does C# have static local variables like C++?"

In C++:
void mysub()
{
static double x;
blah; blah;
}

In C++ the variable x retained its value for subsequent entries into the
method

That being the objective, will the following accomplish the same in C sharp?

static void mysub()
{
double x;
blah; blah;
}

No, it won''t, and no, static locals aren''t supported in C#.

Willy.


这篇关于Static方法的变量也是staic吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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