控件中国网现已改版,您看到的是老版本网站的镜像,系统正在为您跳转到新网站首页,请稍候.......
中国最专业的商业控件资讯网产品咨询电话:023-67870900 023-67871946
产品咨询EMAIL:SALES@COMPONENTCN.COM

浅谈 C# 交互窗口

作者:佚名 出处:互联网 2010年12月01日 阅读:

浅谈 C# 交互窗口
我们知道,F# 的编译器是 fsc.exe,F# 交互窗口是 fsi.exe。其他动态语言也可以交互执行,例如 Ruby 语言的解释器是 ruby,交互窗口是 irb。而 Python 语言中,python 既可以解释执行,也可以作为交互窗口。

C# 语言虽然不是动态语言,但是在 mono 中也有一个 C# 交互窗口: csharp 。

ben@ben1520:~> csharp
Mono C# Shell, type "help;" for help

Enter statements below.
csharp> Environment.Version;
4.0.30319.1
csharp> Environment.OSVersion;
Unix 2.6.34.7
csharp> var pi = Math.PI;
csharp> pi / 2;
1.5707963267949
csharp> ShowVars();
double pi = 3.14159265358979
csharp> quit;
ben@ben1520:~>

 
可以看出,直接输入一个表达式,C# 交互窗口就会给出该表达式的值。使用 help 命令可以获得帮助:

ben@ben1520:~> csharp
Mono C# Shell, type "help;" for help

Enter statements below.
csharp> help;
"Static methods:
  Describe (object)       - Describes the object's type
  LoadPackage (package);  - Loads the given Package (like -pkg:FILE)
  LoadAssembly (assembly) - Loads the given assembly (like -r:ASSEMBLY)
  ShowVars ();            - Shows defined local variables.
  ShowUsing ();           - Show active using declarations.
  Prompt                  - The prompt used by the C# shell
  ContinuationPrompt      - The prompt for partial input
  Time(() -> { })         - Times the specified code
  quit;                   - You'll never believe it - this quits the repl!
  help;                   - This help text
  TabAtStartCompletes - Whether tab will complete even on emtpy lines
"
csharp> ShowUsing();
using System;
using System.Linq;
using System.Collections.Generic;
using System.Collections;
csharp> quit;
ben@ben1520:~>

 
下面是使用 Linq 语句的例子:

ben@ben1520:~> csharp
Mono C# Shell, type "help;" for help

Enter statements below.
csharp> using System.IO;
csharp> from f in Directory.GetFiles("/etc")
      > let fi = new FileInfo(f)
      > where fi.LastWriteTime > DateTime.Now.AddDays(-7)
      > select f;
{ "/etc/adjtime",  "/etc/fstab", "/etc/group","/etc/mtab", "/etc/passwd", "/etc/shadow" }
csharp> quit;
ben@ben1520:~>

 
此外,C# 交互窗口还支持编辑命令行,<Home>键移动光标到行首,<End>键移动光标到行末,<上箭头>键将当前行替换为上一行,<下箭头>键将当前行替换为下一行,<退格>键删除光标前一个字符,<Del>键删除光标处字符,<Tab>键补全命令行。更详细的信息可使用 man csharp 命令查看。

ben@ben1520:~/work> cat test.cs
using System.Numerics;
var a = 13;
BigInteger.Pow(a, 53);
ben@ben1520:~/work> csharp test.cs -r:System.Numerics.dll
109395050288514219040366056833567359441133418834382438145053
ben@ben1520:~/work> csharp --version
Mono C# compiler version 4.0.0.0
ben@ben1520:~/work>

 
可见也可以将 C# 语句放到 .cs 文件中由 csharp 来解释执行。
 

热推产品

  • ActiveReport... 强大的.NET报表设计、浏览、打印、转换控件,可以同时用于WindowsForms谀坔攀戀Forms平台下......
  • AnyChart AnyChart使你可以创建出绚丽的交互式的Flash和HTML5的图表和仪表控件。可以用于仪表盘的创......
首页 | 新闻中心 | 产品中心 | 技术文档 | 友情连接 | 关于磐岩 | 技术支持中心 | 联系我们 | 帮助中心 Copyright-2006 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 电话:023 - 67870900 传真:023 - 67870270 产品咨询:sales@componentcn.com 渝ICP备12000264号 法律顾问:元炳律师事务所 重庆市江北区塔坪36号维丰创意绿苑A座28-5 邮编:400020
在线客服
在线客服系统
在线客服
在线客服系统