Thursday, June 26, 2014

Roslyn (Next Version of C# Compiler ) part 01

This article is about what is available in C# 6.0 with next version of compiler. You can have the binaries from roslyn.codeplex.com and use it. Here im going to demonstrate some key futures that useful in day to day programming .


1. Indexed Members and Element Initializers

There is several versions of it. Here is example for assign collection when it initialize in the code,
Ex : List<Ttype,Tvalue>

 Dictionary<string, string> sampleDemo = 
    new Dictionary<string, string>()
  {
    {"Mango", "Yellow"},
    {"Banana", "Green"},
    {"Pineapple", "Orange"},
    {"Apple", "Red"}
  };

//You can access each element like here
var c = sampleDemo ["Mango"];


indexed Members with $ mark

 Dictionary<string, string> sampleDemo = 
    new Dictionary<string, string>()
  {
    $Mango="Yellow",
    $Banana="Green",
    $Pineapple="Orange",
    $Apple="Red"
  };

//You can access each element like here
var c = sampleDemo.$Mango;

indexing with Json data

Code:
string JsonData =@"{"widget": {
    "debug": "on",
    "window": {
        "title": "Sample Konfabulator Widget",
        "name": "main_window",
        "width": 500,
        "height": 500
    },
    "image": { 
        "src": "Images/Sun.png",
        "name": "sun1",
        "hOffset": 250,
        "vOffset": 250,
        "alignment": "center"
    },
    "text": {
        "data": "Click Here",
        "size": 36,
        "style": "bold",
        "name": "text1",
        "hOffset": 250,
        "vOffset": 100,
        "alignment": "center",
        "onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;"
    }
}}";



//You can access each element like here
JObject jObject = JObject.Parse(JsonData );
  var output = jObject.$window.$Keyword);




Thanks and enjoy... Meet with next post with another feature

0 comments:

Post a Comment