MicrosoftDocs / bing-docs

Other
12 stars 40 forks source link

Bad code example, please improve #185

Open waynebaby opened 8 months ago

waynebaby commented 8 months ago

In the document:

        // Create a query
        ...
        var queryString = HttpUtility.ParseQueryString(string.Empty);
        queryString["q"] = userQuery;
        var query = "https://api.bing.microsoft.com/v7.0/search?" + queryString;
        ...

the code is depending on an implementation of ToString() in a private class HttpQSCollection, which is never descripted in any documents. NameValueCollection was never guaranteed returning a query string liked string. By the context, the code can be easily replaced by

var query =$"https://api.bing.microsoft.com/v7.0/search?q={userQuery}";

Document Details

Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.