label1.Font = new System.Drawing.Font(label1.Font, FontStyle.Bold);
Search This Blog
Thursday, February 7, 2013
Tuesday, January 29, 2013
?: Operator (Ternary) (C#)
C# > Operators > Ternary (?:)
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:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private string OddOrEven(int x)
{
return (x % 2 == 0) ? "Number is even" : "Number is odd";
}
private void Form1_Load(object sender, EventArgs e)
{
string s;
s = OddOrEven(10); // Number is even
s = OddOrEven(11); // Number is odd
}
}
}
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
{public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private string OddOrEven(int x)
{
return (x % 2 == 0) ? "Number is even" : "Number is odd";
}
private void Form1_Load(object sender, EventArgs e)
{
string s;
s = OddOrEven(10); // Number is even
s = OddOrEven(11); // Number is odd
}
}
}
Etichete:
c#
Verbatim String Literals (C#)
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:
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.
string path = @"C:\Programs\MyProgram\My.exe";
Etichete:
c#
Escape sequences (C#)
C# > Escape sequences
The special escape character is the backslash character (\).
\" Display a double quotation mark.The special escape character is the backslash character (\).
\' Display a single quotation mark.
\\ Display a backslash.
\0 Null
\a Alarm
\b Backspace
\f Form feed
\n Newline
\r Carriage return
\t Tab
\v Vertical tab
Result is:
Dan said: "Hello world!"
string path = "C:\\MyDir";
Result is:
C:\MyDir
Etichete:
c#
Filter DataTable with LINQ (Visual Basic)
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim dt As DataTable = New DataTable("table")
dt.Columns.Add("id", Type.GetType("System.Int32"))
dt.Columns.Add("name", Type.GetType("System.String"))
Dim dr As DataRow = dt.NewRow()
dr("id") = 1dr("name") = "john"
dt.Rows.Add(dr)
dr = dt.NewRow()
dr("id") = 2dr("name") = "dan"
dt.Rows.Add(dr)
Dim filteredTable As DataTable = (From n In dt.AsEnumerable()
Where n.Field(Of Int32)("id") = 1Select n).CopyToDataTable()
ComboBox1.DataSource = filteredTable
ComboBox1.DisplayMember = "name"
ComboBox1.ValueMember = "id"
End Sub
End Class
Etichete:
VB.NET
Thursday, January 24, 2013
Regular expression pattern Split method in C#
C# > Text > Regular Expressions > Split
Splits an input string into an array of substrings at the positions defined by a regular expression pattern.
Splits an input string into an array of substrings at the positions defined by a regular expression pattern.
Example:
string path = "some_text_words";
string[] substrings = Regex.Split(path, "_");
foreach (string match in substrings)
{ }
Etichete:
c#
Wednesday, January 23, 2013
Database Mail Views (SQL Server)
SQL Server > Catalog Views > Database Mail
These views are located in the msdb database.
Database Mail has views for displaying Database Mail e-mails information such as status of e-mails, any messages received and errors logged by Database Mail.
sysmail_allitems
Contains one row for each message processed by Database Mail.
Important columns
sysmail_faileditems
Contains information about messages were not successfully sent.
Has the same colums as but sent_status value is always failed.
To view the reason for the failure see onformation in the sysmail_event_log view.
sysmail_event_log
Contains one row for each message returned by the Database Mail system.
When troubleshooting Database Mail, search in sysmail_event_log view for events related to e-mail failures.
Important columns:
These views are located in the msdb database.
Database Mail has views for displaying Database Mail e-mails information such as status of e-mails, any messages received and errors logged by Database Mail.
sysmail_allitems
Contains one row for each message processed by Database Mail.
Important columns
Name
|
Description
|
mailitem_id
|
Identifier
of the mail item in the mail queue.
|
profile_id
|
The
identifier of the profile used to send the message.
|
recipients
|
The e-mail
addresses of the message recipients.
|
subject
|
The
subject line of the message.
|
body
|
The body
of the message.
|
sent_status
|
The status
of the mail. Possible values are:
|
sent_date
|
The date
and time that the message was sent.
|
sysmail_faileditems
Contains information about messages were not successfully sent.
Has the same colums as but sent_status value is always failed.
To view the reason for the failure see onformation in the sysmail_event_log view.
sysmail_event_log
Contains one row for each message returned by the Database Mail system.
When troubleshooting Database Mail, search in sysmail_event_log view for events related to e-mail failures.
Important columns:
event_type
|
Errors,
warnings, informational messages, success messages
|
log_date
|
The date
and time the log entry is made.
|
description
|
The text
of the message being recorded.
|
mailitem_id
|
Identifier
of the mail item in the mail queue.
|
Etichete:
SQL Server
Subscribe to:
Posts (Atom)