首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Nemerle中的输入

Nemerle中的输入
EN

Stack Overflow用户
提问于 2009-09-13 01:02:55
回答 2查看 317关注 0票数 1

我想知道如何从表单的控制台获取输入:

M146599在nemerle。在C#中,我通过以下方式做到这一点:

代码语言:javascript
复制
            string[] input = System.Console.ReadLine().Split(' ');
            ch = System.Char.Parse(input[0]);
            a  = System.Int32.Parse(input[1]);
            d =  System.Int32.Parse(input[2]);
            m =  System.Int32.Parse(input[3]);

但这在内梅尔是行不通的。请建议我如何在Nemerle中做到这一点。

EN

回答 2

Stack Overflow用户

发布于 2009-09-13 10:30:55

代码语言:javascript
复制
class Test
{
  public static Main () : void
  {
    def input = System.Console.ReadLine ().Split (' ');
    def ch = System.Char.Parse (input[0]);
    def a  = System.Int32.Parse (input[1]);
    def d =  System.Int32.Parse (input[2]);
    def m =  System.Int32.Parse (input[3]);

    System.Console.WriteLine ("ch:{0} a:{1} d:{2} m:{3}",  ch, a, d, m);
  }
}
票数 5
EN

Stack Overflow用户

发布于 2009-11-04 06:42:28

您还可以使用IO宏:

代码语言:javascript
复制
using Nemerle.IO;
using System;

mutable ch, a, d, m;
try
{
    scanf("%c %d %d %d", ch, a, d, m);
    printf("%c %d %d %d\n", ch, a, d, m);
}
catch
{
    | _ is InvalidInput => Console.WriteLine("Invalid input")
}

注意,与C++不同的是,Nemerle版本的printf和scanf是安全的。只有在传递正确类型的参数时,它们才会被编译。在上面的示例中,甚至可以从用法中推断出正确的类型。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1416577

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档