Monday, March 18, 2013

c# split list into sub lists

public static List<List<T>> Split<T>(List<T> source)
        {
            return source
                .Select((x, i) => new { Index = i, Value = x })
                .GroupBy(x => x.Index / 4)
                .Select(x => x.Select(v => v.Value).ToList())
                .ToList();
        }

Read file content with File reader

 using (StreamReader stream = File.OpenText(PathOfFile))
            {
                string fileContentsDatas = stream.ReadToEnd();
}

Friday, February 1, 2013

Fluient nhibernet syntaxes

After a long time working on nhibernet fluient
I like that much with c# syntax
It is really good rather than the normal syntax with xmles

Handlin radio button with value javascript

<script type="text/javascript">
    function Str() {
        var theSelectedRadio = document.getElementsByName("x");       
        for (var i = 0; i < theSelectedRadio.length; i++) {           
            if (theSelectedRadio[i].checked) {
                alert(theSelectedRadio[i].value);
            }
        }       
    }
    </script>

<body>
</body>


<input id="x" type="radio" name="x" value="true" />
    <input id="y" type="radio" name="x" value="false" />
    <input id="z" type="radio" name="x" value="NotSelected" />
    <input type="radio" name="x" value="NotSelectedThere" />
    <input type="button" value="s" onclick="Str()" />