当前位置:文档之家› 天津理工大学C#试验一

天津理工大学C#试验一

实验报告
static void Main(string[] args)
{
Console.WriteLine("第̨²一°?个?C#程¨¬序¨°!ê?!ê?");
Console.ReadLine();
}
}
}
2、
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace实验1.2
{
class Program
{
static void Main(string[] args)
{
int a = 345;
float b = 15.3f;
bool c = true;
char d = 't';
string e = "12345";
Console.WriteLine("int a = " + a);
Console.WriteLine("float b = " + b);
Console.WriteLine("bool c = " + c);
Console.WriteLine("char d = " + d);
Console.WriteLine("string e = " + e);
//转Áa换?
Console.WriteLine("\n类¤¨¤型¨ª转Áa换?\n");
Console.WriteLine("\n整?型¨ª转Áa化¡¥为a长¡è整?型¨ª:êo\n");
long l = a;
Console.WriteLine("long l = a = " + l);
3、
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace实º¦Ì验¨¦1._3
{
class Program
{
public static void swamp(ref int x,ref int y) {
int temp = x;
x = y;
y = temp;
4、
using System;
using System.Collections.Generic; using System.Linq;
using System.Text;
namespace实º¦Ì验¨¦1._4
{
class MainClass
{
public interface Body
{
float area();
}
class Cube : Body
{
public Cube(float x1) {
a = x1;
}
public float a;
void setA(float x)
{
a = x;
}
public float area()
return 6 * a * a;
}
}
class Ball : Body
{
public Ball(float r1)
{
r = r1;
}
float r;
void setR(int r1)
{
r = r1;
}
public float area()
{
return (float)(4 * 3.14 * r * r);
}
}
public static float getArea(Body b)
{
return b.area();
}
static void Main(string[] args)
{
Cube c1 = new Cube(2);
Ball b1 = new Ball(3);
Console.WriteLine("Cube.area = " + getArea(c1));
Console.WriteLine("Ball.area = " + getArea(b1)); }
}
}
6、
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace实º¦Ì验¨¦1._6
{
class Program
{
static void Main(string[] args)
{
//Contains
string s = "葫¨´芦?娃ªT,ê?葫¨´芦?娃ªT,ê?一°?根¨´藤¬¨´上¦?七?朵?花¡§";
bool b = s.Contains("葫¨´芦?娃ªT");
Console.WriteLine(b);
bool c = s.Contains("");//空?字Á?符¤?串ä?也°2返¤¦Ì回?True
Console.WriteLine(c);
bool d = s.Contains("哪?吒?");
Console.WriteLine(d);
//Split
string data = "2017-4-16";
string[] t = data.Split('-');
foreach(string str in t)
Console.WriteLine(str);
//join
string time = string.Join("/",t);
Console.WriteLine(time);
string s1 = "猴?哥?,";
string s2 = "你?真?了¢?不?得Ì?";
Console.WriteLine(string.Concat(s1, s1, s2));
//IndexOf
Console.WriteLine(data.IndexOf("4"));
//Copy
见?牛¡ê羊¨°";
string d4 = string.Copy(s3);
Console.WriteLine(d4);
//Clone
string s4 = "猴?哥?,ê?猴?哥?,ê?你?真?了¢?不?得Ì?";
object s5 = s4.Clone();
Console.WriteLine(s5.ToString());
}
}
}
五、心得体会
自从上了大学也学了几门计算机语言了,感觉基础操作大同小异。

C#前几章的内容和其他语言也没太大差别,其中的一些方法记住就好了。

只不过时间久了不用会忘掉,拿起来看看就会了。

C#的过人之处应该就是后边几章吧,记得之前学前端,各种界面都是用代码画出来的,C#中只要添加各种元素就好了,真的好方便。

虽然是一门选修,但是老师讲的特别好,希望跟着老师能学到点东西,以后不会丢老师的脸,不丢理工的脸。

相关主题