开始学习C#

来源:互联网 发布:边伯贤直播软件 编辑:程序博客网 时间:2024/06/07 13:31

由于项目需要,最近开始从新学习C#,之前上课没有认真学习过,所以名为重新学习,其实很多都是新学。今天用if ()else { }语句编写一个简单的函数程序。写完之后发现不能识别小数,于是在网上搜了一下,终于可以将小数识别出来,很简单。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main()
{
Console.WriteLine(“please enter the value of x:”);
string i = Console.ReadLine();
float x = Convert.ToSingle(i);
int y;
if (x > 0) y = +1;
else if (x == 0) y = 0;
else y= -1;
Console.WriteLine(“The value of y is {0}”, y);
Console.ReadLine();

    }}

}
下表列出了 Convert 类中可使用的一些方法。
数值类型
方法
decimal
ToDecimal(String)
float
ToSingle(String)
double
ToDouble(String)
short
ToInt16(String)
int
ToInt32(String)
long
ToInt64(String)
ushort
ToUInt16(String)
uint
ToUInt32(String)
ulong
ToUInt64(String)
只要将string转化的那句稍微改变一下,即可识别小数!

0 0