c#string声明问题
cxmin 2009-04-03 09:54:51 我编了一个简单的c#程序,用csc编译一下发现出错。程序如下。
using System;
using System.Collections.Generic;
using System.Text;
class Test
{
//private string str2;
static void Main(string[] args)
{
private string str1 = "Hello World";//不能用private,为什么。
string str2 = str1.Substring(0,1);
Console.WriteLine(str2);
}
}
这是错误提示:
Microsoft (R) Visual C# 2005 编译器 版本 8.00.50727.1433
用于 Microsoft (R) Windows (R) 2005 Framework 版本 2.0.50727
版权所有 (C) Microsoft Corporation 2001-2005。保留所有权利。
testsubstring.cs(20,3): error CS1513: 应输入 }
testsubstring.cs(23,20): error CS1519: 类、结构或接口成员声明中的标记“(”无效
testsubstring.cs(23,25): error CS1519: 类、结构或接口成员声明中的标记“)”无效
testsubstring.cs(26,1): error CS1022: 应输入类型、命名空间定义或文件尾
请按任意键继续. . .
请问各位为什么str1不能声明为私有。不是说C#默认变量为私有吗??