search in wikipedia the tallest building in the world in csharp

To search for the tallest building in the world on Wikipedia using C#, you can use the Wikipedia API. Here's an example code using web requests and parsing the JSON response to retrieve the information you need:

main.cs
using System;
using System.Net;
using System.IO;
using Newtonsoft.Json.Linq;

public static void Main()
{
    // API endpoint
    string apiUrl = "https://en.wikipedia.org/w/api.php?action=opensearch&search=Tallest%20building%20in%20the%20world&limit=1&namespace=0&format=json";

    // Create a web request to the API endpoint
    HttpWebRequest request = (HttpWebRequest) WebRequest.Create(apiUrl);
    request.Method = "GET";

    // Get the response from the API
    HttpWebResponse response = (HttpWebResponse) request.GetResponse();
    StreamReader reader = new StreamReader(response.GetResponseStream());
    string jsonResponse = reader.ReadToEnd();

    // Parse the JSON response and retrieve the title of the first result
    JObject json = JObject.Parse(jsonResponse);
    JArray results = (JArray) json["1"];
    string title = (string) results[0];

    // Display the results to the console
    Console.WriteLine("The tallest building in the world is {0}.", title);
}
983 chars
28 lines

This code requests the Wikipedia API for the search term "Tallest building in the world" and retrieves the first result. It then parses the JSON response and displays the title of the first result to the console. Note that you'll need to include the Newtonsoft.Json package in your project to use the JObject class.

gistlibby LogSnag