c#初学简单程序实例
,
1基本输入输出
static void main(string[] args)
{
console.writeline("输入点啥吧");
string s=console.readline();
console.writeline("欢迎光临"+s);
console.readline();
}
[csharp]
2,结构类型的使用
namespace
{
struct student
{
public string stu_id;
public string name;
public int age;
public int score;
}
class program
{
static void maini(string[] args)
{
student s;
s.stu_id='' 09306101'';
s.name=''小红'';
s.age=29;
s.score=99;
console.writeline(''学号:''+s.stu_id);
console.readline();
}
}
}
[csharp]
3,数组的使用,求数组最大最小值
static void mian(string[] args)
{
int max,min;
int[] a=new int[10]{1,24,3,72,37,45,41,5,44,8};
max=a[0];
min=a[0];
for(int i=1;i<a.length;i++)
{
if(max<a[i])
max=a[i];
if(min>a[i])
min=a[i];
}
comsole.writeline(''最大值{0}'',max);
comsole.writeline(''最小值{0}'',miin);
console.readline();
}
}
}
[csharp] view plaincopyprint?
4,string常用方法
static void main(string[] args)
{
console.writeline("请输入用户名:");
string s=console.readline();
if(string.compare(s,''wxy'')==0)
{
console.writeline('' 开始演示方法了:");
string str='' hello'';
console.writeline("复制字符串:{0},string.copy(str1));
console.writeline("字串:{}",str.substring(3.2));
console.writeline("插入:{0}'',str1.insert(3,"******"));
}
else
{
console.writeline("用户名错误,退出程序");
}
console.readline();
}}}
[csharp]
5,显式转换和隐式转换
static void main(string[] args)
{
console.writeline("隐式转换:");
short i=1234;
console.writeline(i);
int s=i;
console.writeline(s);
console.writeline("显式转换:");
long l=12345;
console.writeline(l);
int l1=(int)l;
console.writeline(l1);
console.readline();
}
[csharp]
6,装箱和拆箱
static void main(string[] args)
{
int i=123;
object obj=123;
int j=(int)obj;
console.writeline("x={0}",i);
console.writeline("obj={0}",obj);
console.writeline("j={0}",j);
console.readline();
}
补充:软件开发 , C# ,