1. 请写一个函数,计算字符串的长度.
答:
int strlen(const char* src){
assert( NULL != src);
int len = 0;
while(*src++ != '\0')
len++;
return len;
}现在要求把这个函数变成C#的(不得使用类库)
答:
int strlen(const char* src){
assert( NULL != src);
int len = 0;
while(*src++ != '\0')
len++;
return len;
}现在要求把这个函数变成C#的(不得使用类库)
解决方案 »
- 求助怎么写个自动生成订单的函数
- HttpWebRequest =========CookieCollection =========cookies 设置
- C# listview跪求实现方法.求包养!
- HttpWebRequest 问题
- 各位大哥救救我,建项目时出现以下错误,谢谢指教!!!
- 求教dll中的控件,如何引用到样式?
- 我用Polygon、Ellipse,为什么出现“未能找到类型或命名空间名称”错误???????????
- 应该用哪个事件使DataGridView中的两个值的的乘积在另外一个中马上显示出来
- 出差在外,各位网友大救命!
- C#如何得到当前文件目录?第一个回答正确者得分20
- 求教 :字符串写法
- 我想问一下,递归的问题
int i = -1;
while(true) {
try {
str[++i];
}catch(IndexOutOfRangeException) {
break;
}
}
return i;
{
int len = 0, i=0;
byte[] chStr = Encoding.ASCII.GetBytes( src );
try
{
while (chStr[i++] != '\0')
len++;
}
catch { }
return len;
}
C#不使用类库寸步难行~
{
System.Diagnostics.Debug.Assert(null != src); int len = 0;
while (*src++ != '\0')
len++; return len;
}
{
System.Diagnostics.Debug.Assert(null != src); int len = 0; fixed (char* pSrc = src)
{
char* p = pSrc;
while (*p++ != '\0')
len++;
} return len;
}