Ternary (conditional) operator (?:) returns one of two values depending on the value of a Boolean expression.
The syntax for the ternary operator is
condition ? first_expression : second_expression;
Example:
namespace WindowsFormsApplication1
{ publicpartialclassForm1 : Form { public Form1() { InitializeComponent(); } privatestring OddOrEven(int x) { return (x % 2 == 0) ? "Number is even" : "Number is odd"; } privatevoid Form1_Load(object sender, EventArgs e) { string s; s = OddOrEven(10); // Number is even s = OddOrEven(11); // Number is odd } } }
C# > Verbatim String Literals In a verbatim string literal, the characters between the delimiters are interpreted verbatim, the only exception being a quote-escape-sequence.
Suppose you want to set a string as following:
string path = "C:\\Programs\\MyProgram\\My.exe";
You can use the verbatim string literal character (@) to build the string exactly as it appears within the double quotation marks.
VB.NET > Data > DataTable > Filter with LINQ Use AsEnumerable method to return the input type DataTable as IEnumerable. The CopyToDataTable method takes the results of a query and copies the data into aDataTable.
Example:
PublicClassForm1
PrivateSub Form1_Load(sender AsObject, e AsEventArgs) HandlesMyBase.Load
Dim dt AsDataTable = NewDataTable("table") dt.Columns.Add("id", Type.GetType("System.Int32")) dt.Columns.Add("name", Type.GetType("System.String"))
Dim dr AsDataRow = dt.NewRow()
dr("id") = 1 dr("name") = "john" dt.Rows.Add(dr)
dr = dt.NewRow()
dr("id") = 2 dr("name") = "dan" dt.Rows.Add(dr)
Dim filteredTable AsDataTable = (From n In dt.AsEnumerable()