里面的sb1.Append((char)i);
sb1.Append("");是什么意思呢

解决方案 »

  1.   

    往结尾添加字符串
    例子中会生成一个长度为200的字符串,内容就是前100个asscii码字符分别加一空格
      

  2.   

    生成的字符串前几个字符是显示不了的,取中间一段做示例吧:
    "...A B C D E ...a b c ..."这个样子的
      

  3.   

    看来还真是0基础,之前没学过C或Basic什么的?
      

  4.   

    sb1.Append((char)i); //这一行是往sb1创建的字符串结尾加上一个字符,这个字符就是数字i对应的ascii码,比如65对应A
    sb1.Append(" ");//这一行是在字符串结尾加上一个空格
      

  5.   

    namespace test5
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine("请输入生日日期:(例如:2000-01-01或2000/01/01)");
                int year=int.Parse (Console.ReadLine());
                int month=int.Parse (Console .ReadLine());
                int day=int.Parse(Console.ReadLine ());
                DateTime birthday=new DateTime(year,month,day);
                Console.WriteLine("你的年龄是:{0}周岁,GetAge(birthday)");
            }
            public static int GetAge(DateTime birthday);
            {
              int x=DateTime.Today.Year ;
              int y=DateTime.Today.Month;
              int z=DateTime.Today.Day ;
            if(z<birthday.day)
               y--;
            if(y<birthday.month)
               x--;
            return y-birthday.year;
          {
      

  6.   

    这个程序我想要用户自己输入生日日期
    可是这里  if(z<birthday.day)
               y--;
            if(y<birthday.month)
               x--;
            return y-birthday.year;
          {
    总是报错
      

  7.   

    你不能光看书。
    你提的这个问题,其实本不该提,提了就说明了你学习方法不对。
    sb1.Append("")是什么意思?你打开visual studio ,输入这些代码,然后按F12,文档帮助会告诉你,这个方法是什么意思。==========
    最新文章:浅谈C#数组(一) https://mp.weixin.qq.com/s/76LPgHgCYs8FPX3dAl9w6w
    欢迎关注微信公众号 “产品技术知与行” ,解读技术经典书籍(C#,Java,Js),发表技术专题、提供源码下载,打造全面结构化知识库,欢迎对全栈/跨语言技术有兴趣的小伙伴关注。
      

  8.   

    这个程序我想要用户自己输入生日日期
    可是这里  if(z<birthday.day)
               y--;
            if(y<birthday.month)
               x--;
            return y-birthday.year;
          {
    总是报错
    日期计算哪有那么简单,如果生日是1月怎么减?你得好好看看算法。
    c#有做日期计算的方法
      

  9.   

    计算年龄
     var asas=(DateTime.Today-new DateTime(2017,3,19)).Days;
                int age = 0;
                if (asas%365==0)
                {
                    age = asas / 365;
                }
                else
                {
                    age = asas / 365+1;
                }
      

  10.   

    这个程序我想要用户自己输入生日日期
    可是这里  if(z<birthday.day)
               y--;
            if(y<birthday.month)
               x--;
            return y-birthday.year;
          {
    总是报错
    日期计算哪有那么简单,如果生日是1月怎么减?你得好好看看算法。
    c#有做日期计算的方法
    那我的程序要怎么改啊
      

  11.   

    月日可以一起判断
    double  monthDay = birthday.month+day/100;
    double  monthDayNow  = DateTime.today.month+DateTime.today.day/100;
    if(monthDay >=monthDayNow  )
     return y-birthday.year;
    else
      return y-birthday.year-1;
      

  12.   

    namespace test5
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine("请输入生日日期:(例如:2000-01-01或2000/01/01)");
                int year=int.Parse (Console.ReadLine());
                int month=int.Parse (Console .ReadLine());
                int day=int.Parse(Console.ReadLine ());
                DateTime birthday=new DateTime(year,month,day);
                Console.WriteLine("你的年龄是:{0}周岁,GetAge(birthday)");
            }
            public static int GetAge(DateTime birthday);
            {
               var days=(DateTime.Today-birthday).Days;
                int age = 0;
                if (days%365==0)
                {
                    age = days/ 365;
                }
                else
                {
                    age = days/ 365+1;
                }
                return age;
            } 
         {
      

  13.   

    随手打的,忘记你定义的是int类型了,先转换下类型在计算
      

  14.   

    namespace ConsoleApplication3
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine("请输入生日日期:(例如:2000-01-01或2000/01/01)");
                int year=int.Parse (Console.ReadLine());
                int month=int.Parse (Console .ReadLine());
                int day=int.Parse(Console.ReadLine ());
                DateTime birthday=new DateTime(year,month,day);
                Console.WriteLine(string.Format("你的年龄是:{0}周岁",GetAge(birthday)));
            }
            public static int GetAge(DateTime birthday)
            {
                int x = DateTime.Today.Year;
                int y = DateTime.Today.Month;
                int z = DateTime.Today.Day;
                double monthDay = birthday.Month + (double)birthday.Day / 100;
                double monthDayNow = DateTime.Today.Month + (double)DateTime.Today.Day / 100;
                if (monthDay > monthDayNow)
                    return x - birthday.Year-1;
                else
                    return x - birthday.Year; 
            }
        }
    }
      

  15.   

     public static int GetAge(DateTime dt) {
                int a = DateTime.Now.Year - dt.Year;
                int runcount = 0;
                int pingcount = 0;
                for (int i = 1; i <= a; i++)
                {
                    if (DateTime.IsLeapYear(dt.Year+i))
                    {
                        runcount++;
                    }
                    else
                    {
                        pingcount++;
                    }
                }
               return runcount + pingcount + 1;
            }
      

  16.   

    (2) 编写程序,定义一个类Cstudent,其中包含:两个私有字段intAge和strName;两个可读写的属性Age和Name;根据年龄返回是否可以被录取的方法Permit(),年龄在18~25岁之间可以被录取;显示对象信息的方法ShowMessage()。
    我还想问问showmessage怎么用
      

  17.   

    建议你多看看书。
    另外这些方法直接在vs里f12,就可以找到使用说明的。
    写程序要会自己琢磨,查资料。
      

  18.   

    我搜了百度没有  和在vs下按了f12说无法导航到showmessage
      

  19.   

    先看一些例子吧,感觉算法都有点模糊就在想着怎么实现,有一个c++地基础,学c#不算很难,我也是新学c#,emmm,因为是工作需要,所以没有系统地去学习,现在还是个半吊子,就百度了下语法还有要用到的api就直接开整了
      

  20.   

    楼主问的都是一些基础知识,首先要搞清楚一些基本概念,什么叫做常量,什么叫做变量,那什么叫做属性、什么叫做方法?什么叫做结构体、什么叫做枚举类型、什么叫做类,public、private、protected各是什么意思,类的继承、封装、多态表示的是什么意思,如何去实现?还有接口是什么东西?还有什么叫面向对象编程?这些东西能否一眼看出来?如果连这些东西都不知道是什么意思,你每看到一个函数就要去论坛问它是干什么的?微软开放的API千千万万,你能记住几个?要学会使用开发文档,并且透过现象看其本质,多多思考,说了这么多,学习方法很重要,而且万丈高楼平地起,投机取巧要不得,不可能一口吃一个胖子!
      

  21.   

    看看你的这段代码
    public static int GetAge(DateTime birthday);
            {
              int x=DateTime.Today.Year ;
              int y=DateTime.Today.Month;
              int z=DateTime.Today.Day ;
            if(z<birthday.day)
               y--;

            if(y<birthday.month)
               x--;

            return y-birthday.year;
          {
    首先是大括号,为啥是一个方向?
    然后按照你这个逻辑如果当前天数比生日天数少,就把当前月份-1;如果当前月份比生日月份小就把当前年份-1,然后现在也不知道x y有没有都-过1,最后用当前月份-生日年份,请问这样的逻辑能走得通吗?
    然后我贴一下我的代码,可供参考,没有做容错处理,我就不分析了:DateTime now = DateTime.Now.Date;
    int year = now.Year - birthday.Year;
    if(now.Month<birthday.Month)
    {
        year--;
    }
    else if(now.Month==birthday.Month&& now.Day<birthday.Day)
    {
        year--;
    }
    return year;