• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
博雅居
要想跟上时代,就得不断学习!
博客园    首页    新随笔    联系   管理    订阅  订阅
创建对象并生成结果的3个步骤-Chapter 3 P38

必须完成3个步骤才能创建对象并生成结果:

1 创建对象
 
namespace LanguageFeatures
{
    public class Product
    {
         
        public int ProductID { get; set; }
        public string Name { get; set; }
        public string Description { get; set; }
        public decimal Price { get; set; }
        public string Category { get; set; }

    }
}

2 设置参数值

  protected string GetMessage()
        {
            //return "Hello.this is a Web Form";
            Product myProduct = new Product();
            myProduct.ProductID = 100;
            myProduct.Name = "Kayak";
            myProduct.Description = "A boat for one person";
            myProduct.Price = 275M;
            myProduct.Category = "Watersports";
            return String.Format("Category:{0}", myProduct.Category );
        }

3返回希望插入到web窗体返回的HTML的值(body部分)

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="LanguageFeatures.Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>Language Features</title>
</head>
<body>
    <h2>Language Features</h2>
    <p><%=GetMessage() %></p>
</body>
</html>

 

If opportunity doesn’t knock, build a door
posted on 2015-10-22 11:18  博雅居  阅读(352)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3