【小正】C#系列随手练,写啥发啥
代码难度不限,长度不限,随手写啥发啥,代码不一定是最简练的,哦也~{:5_92:}随手1:using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Division
{
public float a;
public float b;
}
class Program
{
static void Main(string[] args)
{
const double PI=3.1415927;
Division x = new Division();
x.a = 1;
x.b = 3;
Console.WriteLine("a/b={0:F3}",x.a/x.b);
//Console.ReadLine();
Division y = x;
Console.WriteLine("y====>a/b={0:F3}", y.a / y.b);
Console.WriteLine("PI="+PI);
short c = 32766;
try
{
checked { c += 2; };
//checked { c += 1; };
Console.WriteLine("c=" + c);
}
catch( OverflowException error)
{
Console.WriteLine(error.Message);
}
string s;
Console.WriteLine("Input s:");
s = Console.ReadLine();
Console.WriteLine("s={0}",s);
Console.ReadLine();
}
}
}
随手2:using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
short x = 32766;
ushort y = 65534;
x += 1;
y += 1;
Console.WriteLine("x={0}", x);
Console.WriteLine("y="+ y);
x += 1;
y += 1;
Console.WriteLine("x={0}", x);
Console.WriteLine("y=" + y);
bool a = true;
bool b = false;
Console.WriteLine("a={0}", a);
Console.WriteLine("b=" + b);
a = !b;
Console.WriteLine("a={0}", a);
float c = 3.1415926F;
double d = 3.14159265358979;
Console.WriteLine("c={0}", c);
Console.WriteLine("d={0}", d);
float e = 1.0F;
int f = 2;
Console.WriteLine("e/f=" + e / f);
Console.ReadLine();
}
}
}
随手3:using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication3
{
class Test
{
public string ss = "hello,C#";
public static int count=66;
}
class Program
{
static void Main(string[] args)
{
string tmp;
int rand = new Random().Next(100);
int guess = 0;
int count = 0;
Test tst1 = new Test();
Console.WriteLine(tst1.ss);
Test.count += 4;
Console.WriteLine(Test.count);
do
{
Console.Write("Input a numbet:");
try
{
tmp = Console.ReadLine();
guess = Int32.Parse(tmp.Trim());
if (guess > rand)
{
Console.WriteLine("BIG!");
}
else if (guess < rand)
{
Console.WriteLine("SMALL!");
}
else
{
Console.WriteLine("You`re Right!");
}
}
catch (Exception err)
{
Console.WriteLine(err.Message);
}
} while (guess != rand);
Console.ReadLine();
}
//
}
}
随手4:using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication3
{
class Weigth
{
public static float getweigth()
{
float weight;
Random rand1 = new Random();
weight = (float)rand1.NextDouble();
return weight;
}
}
class Program
{
static void Main(string[] args)
{
int rand = new Random().Next(100);
Console.WriteLine("rand="+rand);
Weigth w1 = new Weigth();
Console.WriteLine("weight="+Weigth.getweigth());
Console.ReadLine();
}
//
}
}
随手5:using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication5
{
class Re_Fun
{
public float mile;
public string road;
private string words="最初的字符串";
//定义类的属性
public string Words
{
get
{
return words ;
}
//set
//{
// words = value;
//}
}
public void test()
{
Console.WriteLine("无参函数");
}
public void test(float Mile,string Road="星际航线")
{
mile = Mile;
road = Road;
Console.WriteLine(mile+road);
}
}
class Program
{
static void Main(string[] args)
{
Re_Fun rf1 = new Re_Fun();
rf1.test();
rf1.test(5);
rf1.test(8.68F, "西北路");
//rf1.Words = "我给你赋值";
Console.WriteLine("words="+rf1.Words);
Console.ReadLine();
}
}
}
@~风介~明早要比赛了所有队伍都来我们学校了 VNC云平台展示 哈哈{:5_97:} Python_GoWithMe 发表于 2014-10-17 21:34
@~风介~明早要比赛了所有队伍都来我们学校了 VNC云平台展示 哈哈
预祝成功!!!{:7_146:}另外,什么比赛啊?{:5_91:} ~风介~ 发表于 2014-10-17 23:50
预祝成功!!!另外,什么比赛啊?
华北五省计算机{:7_130:} Python_GoWithMe 发表于 2014-10-18 12:18
华北五省计算机
嘿嘿,我在南方{:5_91:} 随手6:using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication6
{
class Car
{
public string color;
public double weigth;
public string Color
{
get
{
return color;
}
set
{
color = value;
}
}
public Car()
{
Color ="red_car";
}
public Car(string cor="innital color")
{
Color = cor;
}
public Car(string cor,double weig=5.5)
{
Color = cor;
weigth = weig;
}
}
class Program
{
static void Main(string[] args)
{
int[] intArray = new int;
intArray = 1;
intArray = (int)3.45;
for (int i = 0; i < intArray.Length; i++)
{
Console.WriteLine("intArray["+i+"]="+intArray);
}
//
Car[] carArray=new Car;
for (int i = 0; i < carArray.Length; i++)
{
carArray = new Car();
}
carArray.Color = "blue_car";
carArray = new Car("golden_car");
carArray = new Car("nb_car",8.889);
Console.WriteLine("carArray=" +carArray.Color+"----" +carArray.weigth);
//
List<string> carLst = new List<string>();
carLst.Add(carArray.color);
carLst.Add(carArray.Color);
foreach(string var in carLst)
{
Console.WriteLine("carlst="+var);
}
for (int i = 0; i < carArray.Length; i++)
{
Console.WriteLine("carArray[" + i + "]=" + carArray.Color);
}
Console.ReadLine();
}
}
}
随手7:using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication7
{
class Program
{
static void Main(string[] args)
{
int[, ,] intArray3 = new int;
int[,] intArray2;
intArray2=new int;
intArray2=23;
int k=1;
Console.WriteLine(intArray2);
for (int i = 0; i < intArray2.GetLength(0); ++i)
{
for (int j = 0; i < intArray2.GetLength(1); ++j)
{
//intArray2 = ++k;
intArray2 = 9989;
}
}
foreach (int l in intArray2)
{
Console.WriteLine("{0,5}",l);
}
Console.ReadLine();
}
}
}
随手8:using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication8
{
publicclassBus
{
publicvoid bus()
{
Console.WriteLine("BUS类函数");
}
}
public class Car:Bus
{
string[] wheels = new string;
publicvoid bus()
{
Console.WriteLine("CAR类函数");
}
public Car()
{
wheels = "轮子0";
wheels = "轮子1";
}
public string this
{
get
{
return wheels;
}
set
{
wheels = value;
}
}
}
class Program
{
static void Main(string[] args)
{
Car car1 = new Car();
Console.WriteLine(car1);
car1="1---1";
Console.WriteLine(car1);
car1.bus();
Console.ReadLine();
}
}
}
随手9:using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
namespace ConsoleApplication9
{
class FromWin:System.Windows.Forms.Form
{
public FromWin()
{
Height = 200;
Width = 500;
Text = "windows窗体-鱼C加油-001";
Button bt1=new Button ();
bt1.Height = 50;
}
}
class Program
{
static void Main(string[] args)
{
FromWin fr = new FromWin();
Application.Run(fr);
}
}
}
@小甲鱼为什么没有C#板块内容嘞?{:7_115:} Python_GoWithMe 发表于 2014-10-20 16:18
@小甲鱼为什么没有C#板块内容嘞?
也是有的,在综合交流区:http://bbs.fishc.com/forum-43-1.html
页:
[1]