andruhovski icon

C# Dictionary to HTML Definition List

andruhovski | PRO | 01/24/19 09:14:38 AM UTC | 0 ⭐ | 710 👁️ | Never ⏰ | []
C# |

970 B

|

None

|

0 👍

/

0 👎

using System;
using System.Collections.Generic;
using System.Text;
 
 
namespace Aspose.HTML.Tutorial
{
    public static class AsposeHelper
    {
        public static string ToDefintionList(
            this Dictionary<string, string> source)
        {
            var sb = new StringBuilder("<dl>");
            foreach (var key in source.Keys)
            {
                sb.Append("<dt>");
                sb.Append(key);
                sb.Append("</dt><dd>");
                sb.Append(source[key]);
                sb.Append("</dd></dl>");
            }
            return sb.ToString();
        }
    }
    
    class Program
    {
        static void Main(string[] args)
        {
            var computerTerms = new Dictionary<string, string>
            {
                { "RAM", "Random Access Memory" },
                { "ROM", "Read-Only Memory" }
            };
            Console.WriteLine(computerTerms.ToDefintionList());
        }
    }
}

Comments