Ví dụ với N=3, sẽ in ra hình tam giá như sau
*
* *
* * *
int n =3; for (int i = 1; i <= n; i++) { for (int j = 1; j <= i; j++) { Console.Write("*"); } Console.Write("\n"); }
Ví dụ với N=3, sẽ in ra hình tam giá như sau
*
* *
* * *
int n =3; for (int i = 1; i <= n; i++) { for (int j = 1; j <= i; j++) { Console.Write("*"); } Console.Write("\n"); }
Bài dưới đây hướng dẫn chúng ta cách rewrite Url để tối ưu hóa SEO cho website
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute(“{resource}.axd/{*pathInfo}”);//Bổ sung route mới, ở trước default route
routes.MapRoute(
name: “Products”,
url: “{Products}/{action}/{id}/{productName}”,
defaults: new { controller = “Products”, action = “Index”, id = UrlParameter.Optional, productName=UrlParameter.Optional }
);routes.MapRoute(
name: “Default”,
url: “{controller}/{action}/{id}”,
defaults: new { controller = “Home”, action = “Index”, id = UrlParameter.Optional }
);
}
public static class StringHelpers
{
public static string ToSeoUrl(this string url)
{
// make the url lowercase
string encodedUrl = (url ?? “”).ToLower();// replace & with and
encodedUrl = Regex.Replace(encodedUrl, @”\&+”, “and”);// remove characters
encodedUrl = encodedUrl.Replace(“‘”, “”);// remove invalid characters
encodedUrl = Regex.Replace(encodedUrl, @”[^a-z0-9]”, “-“);// remove duplicates
encodedUrl = Regex.Replace(encodedUrl, @”-+”, “-“);// trim leading & trailing characters
encodedUrl = encodedUrl.Trim(‘-‘);return encodedUrl;
}
}
// GET: Products/Details/5
public ActionResult Details(int? id, string productName)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Product product = db.Products.Find(id);return View(product);
}
@Html.ActionLink(“Details”, “Details”, new { id = item.ProductID, productName = item.ProductName.ToSeoUrl() })