This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Test Class | |
public class Demo { | |
private string send (String msg) => $"{msg} : Sent."; | |
} | |
// Test Util | |
public class PrivateObject<T> where T : class, new () { | |
private T obj; | |
public PrivateObject () { | |
obj = new T (); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int? total = 100; | |
total ?? 0; //เข้าถึงข้อมูลแบบกำหนดค่า default value หากเป็น null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void Main() | |
{ | |
var pers = new int[] { 100, 101, 102, 109 }; | |
ref var index2 = ref getValue(pers, 2); | |
Console.WriteLine($"index 2 before = { index2 } "); // 102 | |
index2 += 5; | |
Console.WriteLine($"index 2 after = { index2 } "); //107 | |
Console.WriteLine($"index 2 after = { pers[2] } "); //107 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Register(UserProfile userProfile) { | |
//local function | |
Tuple<string, string, int> createMember(string fName, string lName, int Age) => Tuple.Create<string, string, int>(fName, lName, Age); | |
//call local function | |
var newMember = createMember(userProfile.fname, userProfile.lname, userProfile.age); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Old way to create new Tuple object | |
var tp1 = Tuple.Create<string, string, int>("Noppon", "DevRock", 26); | |
Console.WriteLine($" tp1 FName={tp1.Item1}, LName={tp1.Item2}, Age={tp1.Item3}"); | |
//New in C#7.0 | |
var newTuple = ("Noppon", "DevRock", 26); | |
Console.WriteLine($" newTuple FName={newTuple.Item1}, LName={newTuple.Item2}, Age={newTuple.Item3}"); | |
//Tuple Literals | |
var newTupleLiterals = (fname: "Noppon", lname: "DevRock", age: 26); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var dec = 1_000_000_000_000; | |
var hex = 0xAB_CD_EF; | |
var bin = 0b1010_1011_1100_1101_1110_1111; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static bool PatternMatching(object x) { | |
// 'is' pattern variable | |
if (x is int i && i > 0) return true; | |
if (x is string k && k.Trim().Length > 0) return true; | |
if (x is person p && p != null) return true; | |
else return false; | |
// switch statement with pattern 'case' and 'when' | |
switch (x) { | |
case int a when a > 0: return true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Run() | |
{ | |
OutVariables(out int x, out int y); | |
Console.Write($"{x}, {y}"); | |
} | |
void OutVariables(out int x, out int y) => x = (y = 2) * 2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export JAVA_8_HOME=$(/usr/libexec/java_home -v1.8) | |
export JAVA_7_HOME=$(/usr/libexec/java_home -v1.7) | |
alias java7='export JAVA_HOME=$JAVA_7_HOME' | |
alias java8='export JAVA_HOME=$JAVA_8_HOME' | |
#default java8 | |
export JAVA_HOME=$JAVA_8_HOME | |
#credit http://stackoverflow.com/users/1037852/vegard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var QueryString = function () { | |
var query_string = {}; | |
var query = window.location.search.substring(1); | |
var vars = query.split("&"); | |
for (var i = 0; i < vars.length; i++) { | |
var pair = vars[i].split("="); | |
if (typeof query_string[pair[0]] === "undefined") { | |
query_string[pair[0]] = decodeURIComponent(pair[1]); | |
} else if (typeof query_string[pair[0]] === "string") { | |
var arr = [query_string[pair[0]], decodeURIComponent(pair[1])]; |
NewerOlder