如何递增一封信? [英] How to increment a letter?

查看:69
本文介绍了如何递增一封信?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出以下声明:


char letter =''A'';


有没有办法可以增加字母那么B会被退回吗?


谢谢。


Mansi

解决方案




写一个方法怎么样


私有字符增量(字符c)

{

int i = ascii of''c'';

if(i< maxascii)

i ++;

返回asciiconverttochar(i);

}


Nirosh。


"曼西" <马*** @ discussions.microsoft.com>在留言中写道

新闻:B8 ********************************** @ microsof t.com ...

给出以下声明:

char letter =''A'';

有没有办法让我可以增加字母以便返回B吗?

谢谢。

Mansi



或者只是这个 - (char)((int)字母+ 1);


规则 - 出于性能原因总是避免调用方法。调用

方法意味着推送/弹出所有本地堆栈变量 - 对于

CPU来说非常痛苦。


- Sahil Malik
http://www.dotnetjunkies.com/weblog/sahilmalik

Mansi <马*** @ discussions.microsoft.com>在留言中写道

新闻:B8 ********************************** @ microsof t.com ...

给出以下声明:

char letter =''A'';

有没有办法让我可以增加字母以便返回B吗?

谢谢。

Mansi





" Sahil Malik" <共***************** @ nospam.com> aécritdansle message de

news: ef *** ***********@TK2MSFTNGP11.phx.gbl ...

或者只是这个 - (char)((int)字母+ 1); <规则 - 始终避免出于性能原因而调用方法。调用
方法意味着推送/弹出所有本地堆栈变量 - 对于CPU来说非常痛苦。


这条规则非常值得商榷。我建议改为:


规则1:当你确定了一段代码时,总是引入一种方法

可以重复使用而不是在任何地方复制代码,特别是

如果方法体有点模糊(比如你需要获得下一个字母的双重演员)。

规则2:如果你发现了一个使用分析器的性能瓶颈,请尝试

内联该方法并查看它是否有所作为(如果没有,请保留

方法,问题出在其他地方)。


另外,调用方法不会推送/弹出所有本地堆栈变量。 (

导致认为所有变量都在过程中被复制),它推动

并弹出一个堆栈帧,这是一个非常简单而且非常简单的快速操作。

内联代码通常会导致代码效率降低,原因很简单,因为代码会变得更大,并且你开始陷入CPU缓存中。


Bruno。

- Sahil Malik
http://www.dotnetjunkies.com/weblog/sahilmalik

" Mansi" <马*** @ discussions.microsoft.com>在消息中写道
新闻:B8 ********************************** @ microsof t.com。 ..

给出以下声明:

char letter =''A'';

有没有办法我可以增加字母B被退回了吗?

谢谢。

Mansi




Given the following declaration:

char letter = ''A'';

Is there a way that I can increment letter so that ''B'' is returned?

Thanks.

Mansi

解决方案

Hi,

How about writting a method

private char Increment(char c)
{
int i = ascii of ''c'';
if (i<maxascii)
i ++;
return asciiconverttochar(i);
}

Nirosh.

"Mansi" <Ma***@discussions.microsoft.com> wrote in message
news:B8**********************************@microsof t.com...

Given the following declaration:

char letter = ''A'';

Is there a way that I can increment letter so that ''B'' is returned?

Thanks.

Mansi



Or simply this -- (char)((int)letter + 1) ;

Rule - always avoid calling a method for performance reasons. Calling a
method means push/pop of all local stack variables - very painful for the
CPU.

- Sahil Malik
http://www.dotnetjunkies.com/weblog/sahilmalik
"Mansi" <Ma***@discussions.microsoft.com> wrote in message
news:B8**********************************@microsof t.com...

Given the following declaration:

char letter = ''A'';

Is there a way that I can increment letter so that ''B'' is returned?

Thanks.

Mansi




"Sahil Malik" <co*****************@nospam.com> a écrit dans le message de
news: ef**************@TK2MSFTNGP11.phx.gbl...

Or simply this -- (char)((int)letter + 1) ;

Rule - always avoid calling a method for performance reasons. Calling a
method means push/pop of all local stack variables - very painful for the
CPU.
This rule is **very** debatable. I would propose instead:

Rule 1: Always introduce a method when you have identified a piece of code
that could be reused instead of duplicating the code everywhere, especially
if the method body is a bit obscure (like the double cast that you have to
do to get the next letter).

Rule 2: If you identify a performance bottleneck with a profiler, try to
inline the method and see if it makes a difference (if it does not, keep the
method, the problem is elsewhere).

Also, calling a method does not "push/pop all local stack variables" (which
leads to think that all the variables are copied in the process), it pushes
and pops a "stack frame", which is a very simple and very fast operation.
Inlining code often leads to less efficient code, simply because the code
gets bigger and you start to get trashing in the CPU cache.

Bruno.

- Sahil Malik
http://www.dotnetjunkies.com/weblog/sahilmalik
"Mansi" <Ma***@discussions.microsoft.com> wrote in message
news:B8**********************************@microsof t.com...

Given the following declaration:

char letter = ''A'';

Is there a way that I can increment letter so that ''B'' is returned?

Thanks.

Mansi




这篇关于如何递增一封信?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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