Redian新闻
>
问一道C# interview testing quesiton
avatar
问一道C# interview testing quesiton# JobHunting - 待字闺中
a*r
1
class MyClass
{
private int numberOfCalls = 0;
private int numberOfLetters = 0;
static void ReverseString(String strIn)
{
char temp;
for (int i = 0; i < strIn.Length; i++)
{
temp = strIn[i];
strIn[i] = strIn[strIn.Length - i];
strIn[strIn.Length - i] = temp;
}
numberOfCalls++;
Console.WriteLine(String.Format("This function has been called {
0}", numberOfCalls));
}

}
望高人指点上面的程序有何flaws
avatar
f*t
2
1.成员变量应该设成static
2.numberOfLetters多余
3.for (int i = 0; i < strIn.Length; i++) 从头做到尾相当于又把string还原了,
应该是i < strln.Length / 2
4.strIn[strIn.Length - i]当i=0时越界,应该是strIn[strIn.Length - i - 1]
5.MyClass和函数都要加public,否则可能无法从其它namespace访问
6.输出函数自带format功能,不需要string.format()
avatar
a*r
3
Thanks
avatar
l*c
4
from 0 to n,
swap,
==== doing nothing
no reverse

【在 a********r 的大作中提到】
: class MyClass
: {
: private int numberOfCalls = 0;
: private int numberOfLetters = 0;
: static void ReverseString(String strIn)
: {
: char temp;
: for (int i = 0; i < strIn.Length; i++)
: {
: temp = strIn[i];

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。