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:

   1 using System;
   2 
   3 namespace org.bitarus.allowed
   4 {
   5   public class Program
   6   {
   7     public static void Main(string[] args)
   8     {
   9       System.Console.WriteLine("Hello world");
  10     }
  11   }
  12 }

Compile 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

   1 <?xml version="1.0" encoding="utf-8" ?>
   2 <configuration>
   3   <appSettings>
   4     <add key="keyx" value="valuex"/>
   5   </appSettings>
   6 </configuration>

   1 using System.Configuration;
   2 //.....
   3 string valuex = ConfigurationManager.AppSettings["keyx"];
   4 System.Console.WriteLine(valuex);

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 }

CSharp (last edited 2014-01-03 11:39:36 by bl13-226-185)