Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ samples/WebApplication1/src/WebApplication1/wwwroot/lib/

_site/
api_src/
api/
/api/
_themes/
_themes.pdf/
_csharplang/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

// <snippet23>
using namespace System;
int main()
{
char chA = 'A';
char ch1 = '1';
String^ str = "test string";
Console::WriteLine( chA.CompareTo( 'B' ) ); // Output: "-1" (meaning 'A' is 1 less than 'B')
Console::WriteLine( chA.Equals( 'A' ) ); // Output: "True"
Console::WriteLine( Char::GetNumericValue( ch1 ) ); // Output: "1"
Console::WriteLine( Char::IsControl( '\t' ) ); // Output: "True"
Console::WriteLine( Char::IsDigit( ch1 ) ); // Output: "True"
Console::WriteLine( Char::IsLetter( ',' ) ); // Output: "False"
Console::WriteLine( Char::IsLower( 'u' ) ); // Output: "True"
Console::WriteLine( Char::IsNumber( ch1 ) ); // Output: "True"
Console::WriteLine( Char::IsPunctuation( '.' ) ); // Output: "True"
Console::WriteLine( Char::IsSeparator( str, 4 ) ); // Output: "True"
Console::WriteLine( Char::IsSymbol( '+' ) ); // Output: "True"
Console::WriteLine( Char::IsWhiteSpace( str, 4 ) ); // Output: "True"
Console::WriteLine( Char::Parse( "S" ) ); // Output: "S"
Console::WriteLine( Char::ToLower( 'M' ) ); // Output: "m"
Console::WriteLine( 'x' ); // Output: "x"
}

// </snippet23>
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<!-- <Snippet1> -->
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Web.Script.Serialization" %>
<%@ Import Namespace="System.Web.Script.Serialization.TypeResolver.CS" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{

ColorType customObject = new ColorType();
JavaScriptSerializer serializer;

switch(((RadioButtonList)sender).SelectedIndex)
{
case 0:
serializer = new JavaScriptSerializer();
Label1.Text = serializer.Serialize(customObject);
break;
case 1:
serializer = new JavaScriptSerializer(new SimpleTypeResolver());
Label1.Text = serializer.Serialize(customObject);
break;
case 2:
serializer = new JavaScriptSerializer(new CustomTypeResolver());
Label1.Text = serializer.Serialize(customObject);
break;
}
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Type Resolvers</title>
<style type="text/css">
body { font: 10pt Trebuchet MS;
font-color: #000000;
}

.text { font: 8pt Trebuchet MS }
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
Select one of the following serialization types:
<asp:RadioButtonList ID="RadioButtonList1" runat="server" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged" AutoPostBack="True">
<asp:ListItem Value="0">Serialization with no type resolver</asp:ListItem>
<asp:ListItem Value="1">Serialization with the SimpleTypeResolver class</asp:ListItem>
<asp:ListItem Value="2">Serialization with a custom type resolver</asp:ListItem>
</asp:RadioButtonList>
<br />
Note the different resulting serialized strings. The ones that use type resolvers have an extra __type tag.
<hr />
Results:
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td>
<asp:Label ID="Label1" runat="server" ></asp:Label><br />
</td>
</tr>
</table>
<br />
&nbsp;</div>
</form>
</body>
</html>
<!-- </Snippet1> -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
<!-- <Snippet4> -->
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Web.Script.Serialization" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

JavaScriptSerializer serializer;
protected void Page_Load(object sender, EventArgs e)
{
//<Snippet1>
serializer = new JavaScriptSerializer();

// Register the custom converter.
serializer.RegisterConverters(new JavaScriptConverter[] {
new System.Web.Script.Serialization.CS.ListItemCollectionConverter() });
//</Snippet1>
this.SetFocus(TextBox1);
}

protected void saveButton_Click(object sender, EventArgs e)
{
// Save the current state of the ListBox control.
SavedState.Text = serializer.Serialize(ListBox1.Items);
recoverButton.Enabled = true;
Message.Text = "State saved";
}

protected void recoverButton_Click(object sender, EventArgs e)
{
//Recover the saved items of the ListBox control.
ListItemCollection recoveredList = serializer.Deserialize<ListItemCollection>(SavedState.Text);
ListItem[] newListItemArray = new ListItem[recoveredList.Count];
recoveredList.CopyTo(newListItemArray, 0);
ListBox1.Items.Clear();
ListBox1.Items.AddRange(newListItemArray);
Message.Text = "Last saved state recovered.";
}

protected void clearButton_Click(object sender, EventArgs e)
{
// Remove all items from the ListBox control.
ListBox1.Items.Clear();
Message.Text = "All items removed";
}

protected void ContactsGrid_SelectedIndexChanged(object sender, EventArgs e)
{
// Get the currently selected row using the SelectedRow property.
GridViewRow row = ContactsGrid.SelectedRow;

// Get the ID of item selected.
string itemId = ContactsGrid.DataKeys[row.RowIndex].Value.ToString();
ListItem newItem = new ListItem(row.Cells[4].Text, itemId);

// Check if the item already exists in the ListBox control.
if (!ListBox1.Items.Contains(newItem))
{
// Add the item to the ListBox control.
ListBox1.Items.Add(newItem);
Message.Text = "Item added";
}
else
Message.Text = "Item already exists";
}

protected void ContactsGrid_PageIndexChanged(object sender, EventArgs e)
{
//Reset the selected index.
ContactsGrid.SelectedIndex = -1;
}

protected void searchButton_Click(object sender, EventArgs e)
{
//Reset indexes.
ContactsGrid.SelectedIndex = -1;
ContactsGrid.PageIndex = 0;

//Set focus on the TextBox control.
ScriptManager1.SetFocus(TextBox1);
}

protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
// Show/hide the saved state string.
SavedState.Visible = CheckBox1.Checked;
StateLabel.Visible = CheckBox1.Checked;
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Save/Recover state</title>
<style type="text/css">
body { font: 11pt Trebuchet MS;
font-color: #000000;
padding-top: 72px;
text-align: center }

.text { font: 8pt Trebuchet MS }
</style>
</head>
<body>
<form id="form1" runat="server" defaultbutton="searchButton" defaultfocus="TextBox1">
<h3>
<span style="text-decoration: underline">
Contacts Selection</span><br />
</h3>
<asp:ScriptManager runat="server" ID="ScriptManager1" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
Type contact's first name:
<asp:TextBox ID="TextBox1" runat="server" />
<asp:Button ID="searchButton" runat="server" Text="Search" OnClick="searchButton_Click" />&nbsp;
<br />
<br />
<table border="0" width="100%">
<tr>
<td style="width:50%" valign="top" align="center">
<b>Search results:</b><br />
<asp:GridView ID="ContactsGrid" runat="server" AutoGenerateColumns="False"
CellPadding="4" DataKeyNames="ContactID" DataSourceID="SqlDataSource1"
OnSelectedIndexChanged="ContactsGrid_SelectedIndexChanged" ForeColor="#333333" GridLines="None" AllowPaging="True" PageSize="7" OnPageIndexChanged="ContactsGrid_PageIndexChanged">
<Columns>
<asp:CommandField ShowSelectButton="True" ButtonType="Button" />
<asp:BoundField DataField="ContactID" HeaderText="ContactID" SortExpression="ContactID" Visible="False" />
<asp:BoundField DataField="FirstName" HeaderText="FirstName" SortExpression="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="LastName" SortExpression="LastName" />
<asp:BoundField DataField="EmailAddress" HeaderText="EmailAddress" SortExpression="EmailAddress" />
</Columns>
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#999999" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<EmptyDataTemplate>No data found.</EmptyDataTemplate>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:AdventureWorksConnectionString %>"
SelectCommand="SELECT ContactID, FirstName, LastName, EmailAddress FROM Person.Contact WHERE (UPPER(FirstName) = UPPER(@FIRSTNAME))" >
<SelectParameters>
<asp:ControlParameter Name="FIRSTNAME" ControlId="TextBox1" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</td>
<td valign="top">
<b>Contacts list:</b><br />
<asp:ListBox ID="ListBox1" runat="server" Height="200px" Width="214px" /><br />
<asp:Button ID="saveButton" runat="server" Text="Save state" OnClick="saveButton_Click" ToolTip="Save the current state of the list" />
<asp:Button ID="recoverButton" runat="server" Text="Recover saved state" OnClick="recoverButton_Click" Enabled="false" ToolTip="Recover the last saved state" />
<asp:Button ID="clearButton" runat="server" Text="Clear" OnClick="clearButton_Click" ToolTip="Remove all items from the list" /><br />
<br />
<asp:CheckBox ID="CheckBox1" runat="server" Checked="True" OnCheckedChanged="CheckBox1_CheckedChanged"
Text="Show saved state" AutoPostBack="True" /></td>
</tr>
<tr>
<td colspan="2">
<br />
<br />
&nbsp;&nbsp;
<hr />
Message: <asp:Label ID="Message" runat="server" ForeColor="SteelBlue" />&nbsp;&nbsp;<br />
<asp:Label ID="StateLabel" runat="server" Text="State:"></asp:Label>
<asp:Label ID="SavedState" runat="server"/><br />
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdateProgress ID="UpdateProgress1" runat="server">
<ProgressTemplate>
<asp:Image ID="Image1" runat="server" ImageUrl="..\images\spinner.gif" />&nbsp;Processing...
</ProgressTemplate>
</asp:UpdateProgress>
</form>
</body>
</html>
<!-- </Snippet4> -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!-- <Snippet1> -->
<%@ Page Language="C#" %>
<%@ Register Namespace="SamplesCS" TagPrefix="Samples" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>CreateContentTemplateContainer Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1"
runat="server" />
<Samples:CustomUpdatePanel ID="UpdatePanel1"
UpdateMode="Conditional"
GroupingText="This is an UpdatePanel."
runat="server">
<ContentTemplate>
<asp:Calendar ID="Calendar1"
runat="server" />
</ContentTemplate>
</Samples:CustomUpdatePanel>
</div>
</form>
</body>
</html>
<!-- </Snippet1> -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// <snippet23>
using System;

public class CharStructureSample
{
public static void Main()
{
char chA = 'A';
char ch1 = '1';
string str = "test string";

Console.WriteLine(chA.CompareTo('B')); //----------- Output: "-1" (meaning 'A' is 1 less than 'B')
Console.WriteLine(chA.Equals('A')); //----------- Output: "True"
Console.WriteLine(Char.GetNumericValue(ch1)); //----------- Output: "1"
Console.WriteLine(Char.IsControl('\t')); //----------- Output: "True"
Console.WriteLine(Char.IsDigit(ch1)); //----------- Output: "True"
Console.WriteLine(Char.IsLetter(',')); //----------- Output: "False"
Console.WriteLine(Char.IsLower('u')); //----------- Output: "True"
Console.WriteLine(Char.IsNumber(ch1)); //----------- Output: "True"
Console.WriteLine(Char.IsPunctuation('.')); //----------- Output: "True"
Console.WriteLine(Char.IsSeparator(str, 4)); //----------- Output: "True"
Console.WriteLine(Char.IsSymbol('+')); //----------- Output: "True"
Console.WriteLine(Char.IsWhiteSpace(str, 4)); //----------- Output: "True"
Console.WriteLine(Char.Parse("S")); //----------- Output: "S"
Console.WriteLine(Char.ToLower('M')); //----------- Output: "m"
Console.WriteLine('x'.ToString()); //----------- Output: "x"
}
}
// </snippet23>
Loading