小弟之前在用string.Format("Hello {0}. Hi {1}.", "puma", "hent");
在想說為什麼參數可以動態增加,去找了一下資料,才發現C#有一個params的關鍵字
利用這個params關鍵字就可以模擬跟string.Format()一樣的做法了
小弟之前在用string.Format("Hello {0}. Hi {1}.", "puma", "hent");
在想說為什麼參數可以動態增加,去找了一下資料,才發現C#有一個params的關鍵字
利用這個params關鍵字就可以模擬跟string.Format()一樣的做法了
TestMultiParam.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TestMultiParam.aspx.cs" Inherits="Modules_News_test_TestMultiParam" %>
<!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>TestMultiParam</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
<!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>TestMultiParam</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
TestMultiParam.aspx.cs


















Response.Write("<br/><br/>");

//做一個跟string.Format一樣的方法




//使用params,模擬string.Format的用法









執行結果:
參考網址:http://msdn2.microsoft.com/zh-tw/library/w5zay9db(VS.80).aspx