Size: 2730
Comment:
|
Size: 3097
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 97: | Line 97: |
== Format examples == {{{#!highlight csharp using System; public class Test{ public static void Main(String[] args) { int a=123; System.Console.WriteLine( String.Format("{0}",a) ); // 123 System.Console.WriteLine( String.Format("{0:D2}",a) ); //123 System.Console.WriteLine( String.Format("{0:D5}",a) ); // 00123 } } }}} |
CSharp
CSharp is a multi-paradigm programming language encompassing strong typing, imperative, declarative, functional, procedural, generic, object-oriented (class-based), and component-oriented programming disciplines. It was developed by Microsoft within its .NET initiative and later approved as a standard by Ecma (ECMA-334) and ISO (ISO/IEC 23270:2006). C# is one of the programming languages designed for the Common Language Infrastructure. From Wikipedia
Compile code based on csc (CSharp compiler)
Look for the compiler in c:\windows\Microsoft.NET\Framework\<version>\csc.exe
Hello world sample code:
Compile HelloWorld.cs:
csc /t:exe /out:HelloWorld.exe HelloWorld.cs
Build batch file example .NET 4.0
C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe /t:library /out:libx.dll src\_Default.cs src\DALSql.cs src\Global.cs
app.config sample
Copy src/app.config to AppX.exe.config.
JSON library several :net version
http://james.newtonking.com/json
Deserialization example
1 // mcs test.cs /r:Newtonsoft.Json.dll
2 // mono test.exe
3
4 using Newtonsoft.Json;
5 using System;
6
7 public class Reply{
8 public int mnr {get;set;}
9 public int fnr {get;set;}
10 public MSG[] msg {get;set;}
11 }
12
13 public class MSG{
14 public DateX date {get;set;}
15 public string msg {get;set;}
16
17 }
18
19 public class DateX{
20 [JsonProperty("$date")]
21 public long datex { get;set; }
22 }
23
24 public class Program{
25 public static void Main(string[] args){
26 string json = @"{\"mnr\": 1, \"fnr\": 777, \"msg\": [
27 {\"date\": {\"$date\": 1388679281000}, \"msg\": \"AAAAA\"},
28 {\"date\": {\"$date\": 1388678779000}, \"msg\": \"BBBBB\"},
29 {\"date\": {\"$date\": 1388676003000}, \"msg\": \"CCCCC\"}
30 ]}";
31
32 Reply r = JsonConvert.DeserializeObject<Reply>(json);
33 System.Console.WriteLine(String.Format("Fnumber:{0} MNumber:{1}",r.fnr,r.mnr));
34
35 foreach(MSG msg in r.msg) {
36 System.Console.WriteLine(String.Format("MSG:{0} Date:{1} ",msg.msg, msg.date.datex ));
37 }
38 }
39 }