当前位置:编程学习 > C#/ASP.NET >>

问一个很菜的问题。Datetime对象

using system;
class wintop
  {
    static void Main()
       {
        Console.WriteLine("Now Time Is {0}",wintop())
       }

    Public static DateTime wintop()
       {
        return DateTme.Now;
        }
  }

为什么Console.WriteLine  要写入{0}难道是DateTime.Now 返回的是个数组? --------------------编程问答-------------------- 这是c语言的表示方式吧,不关数组的问题吧,0表示第一个参数,1表示第2个,以此类推。 --------------------编程问答-------------------- 占位符 --------------------编程问答-------------------- {0}对应参数非STRING类型时,会自动调用TOSTRING(). --------------------编程问答-------------------- --------------------编程问答-------------------- --------------------编程问答-------------------- 你完全可以使用 Console.WriteLine("Now Time Is " + wintop().ToString())代替。。。 

支持3楼。 --------------------编程问答-------------------- 仅仅代表后面函数的位置在0这个位置上,这是c#的一个占位符{0},和数组无关。 --------------------编程问答-------------------- 还有 感觉 你的程序有点问题编译不了,我改了下:
using System;
using System.Collections.Generic;
using System.Text;

    namespace nowtime
    {
 
          class wintop 
          { 
            static void Main() 
              { 
                Console.WriteLine("Now Time Is {0}",wintoop()); 
                Console.ReadKey ();
              } 

             public  static DateTime wintoop() 
              { 
                return DateTime.Now; 
              }
          } 

       
        
 }
方法和类名一致,容易出问题。 --------------------编程问答-------------------- 这里的{0}是占位符 --------------------编程问答-------------------- 0}是占位符,它相当于C的%c/%d/ %f等,但它是按照变量的类型输出的 --------------------编程问答-------------------- Public static DateTime wintop() 
      { 
        return DateTme.Now; 
        } 

方法类型与返回类型一致吗?? --------------------编程问答-------------------- 输出数据可以有很多个,{0}只是标示输出wintoop() --------------------编程问答-------------------- 一楼正解 --------------------编程问答-------------------- 占位符,语言规则
--------------------编程问答--------------------
引用 14 楼 netchildren 的回复:
占位符,语言规则

tinghaode 
补充:.NET技术 ,  其他语言
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,