对于你们中的一些人来说,这看起来似乎微不足道 - 但请放纵我,因为我似乎在理解如何显示数组元素方面存在严重的心理障碍。
好的,所以我在这里:
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TestCoding._Default" %>
<asp:Content runat="server" ID="FeaturedContent" ContentPlaceHolderID="FeaturedContent">
<section class="featured">
<div class="content-wrapper">
<hgroup class="title">
<h1><%: Title %>.</h1>
<h2>Modify this template to jump-start your ASP.NET application.</h2>
</hgroup>
<p>
<asp:TextBox ID="post_feedback" runat="server" Height="100" Width="500" BackColor="#0066FF" Font-Bold="True" ForeColor="#FF9933" Wrap="False" TextMode="MultiLine" BorderColor="#000099" BorderStyle="Groove" BorderWidth="2"></asp:TextBox>
<br />
<asp:Button ID="Count_Sentences" runat="server" Text="Count Sentences" OnClick="Count_Sentences_Click"/>
<br />
<br />
<asp:Label ID="Num_Sentences" runat="server" Font-Bold="true">How Many Sentences Do we have today?</asp:Label>
</p>
</div>
</section>
</asp:Content>
Default.aspx.cs文件:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace TestCoding
{
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Count_Sentences_Click(object sender, EventArgs e)
{
int post_length = post_feedback.Text.Length;
string[] post_words = post_feedback.Text.Split(' ');
int num_words = post_words.Length;
Num_Sentences.Text = post_feedback.Text + " " + Convert.ToString(post_length) + " and has " + post_words.Length + " words." + post_words[0];
for (int i = 0; i < num_words; i++)
{
Console.WriteLine(post_words[i]);
}
}
}
}
好的,所以我理解Num_Sentences是我在aspx页面中创建的标签 - 在点击按钮时,会调用Count_Sentences_Click例程,它会执行一些&#34; stuff&#34;并将Num_Sentences.Text绑定到一个由不同字符串和其他数据组成的字符串......
在数据绑定之后的一些代码,我打算写下post_words数组中的所有元素......但是它没有那么好用。
到目前为止我发现的似乎是,&#34;哦,你所要做的就是建立一个循环,然后只做Console.WriteLine(arrayname [i])并且所有人都会很好。宇宙&#34;
显然,我在理解如何成功显示数组元素方面遇到了一些问题。我是否需要单独的标签ID才能将其放入或使用什么?我很困惑。 :P