Advertisement
andruhovski

C# Dictionary to HTML Definition List

Jan 24th, 2019
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.97 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5.  
  6. namespace Aspose.HTML.Tutorial
  7. {
  8.     public static class AsposeHelper
  9.     {
  10.         public static string ToDefintionList(
  11.             this Dictionary<string, string> source)
  12.         {
  13.             var sb = new StringBuilder("<dl>");
  14.             foreach (var key in source.Keys)
  15.             {
  16.                 sb.Append("<dt>");
  17.                 sb.Append(key);
  18.                 sb.Append("</dt><dd>");
  19.                 sb.Append(source[key]);
  20.                 sb.Append("</dd></dl>");
  21.             }
  22.             return sb.ToString();
  23.         }
  24.     }
  25.    
  26.     class Program
  27.     {
  28.         static void Main(string[] args)
  29.         {
  30.             var computerTerms = new Dictionary<string, string>
  31.             {
  32.                 { "RAM", "Random Access Memory" },
  33.                 { "ROM", "Read-Only Memory" }
  34.             };
  35.             Console.WriteLine(computerTerms.ToDefintionList());
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement