Here is a simple example of a program in C# that retrieves the latest Bitcoin (BTC) price from an API and displays it on the console:
using System;
using System.Net;
namespace BTCPriceChecker
{
class Program
{
static void Main(string[] args)
{
// API endpoint for retrieving the latest BTC price
string url = "https://api.coindesk.com/v1/bpi/currentprice/BTC.json";
// Send a request to the API endpoint and retrieve the response
WebClient client = new WebClient();
string response = client.DownloadString(url);
// Parse the response and retrieve the current BTC price
dynamic json = Newtonsoft.Json.JsonConvert.DeserializeObject(response);
string price = json.bpi.USD.rate;
// Display the price on the console
Console.WriteLine("The current price of Bitcoin (BTC) is $" + price);
}
}
}
Note: This example uses an API provided by CoinDesk to retrieve the latest BTC price. You may need to install the Newtonsoft.Json NuGet package in order to use the Newtonsoft.Json.JsonConvert.DeserializeObject method.
using System;
using System.Net;
namespace BTCPriceChecker
{
class Program
{
static void Main(string[] args)
{
// API endpoint for retrieving the latest BTC price
string url = "https://api.coindesk.com/v1/bpi/currentprice/BTC.json";
// Send a request to the API endpoint and retrieve the response
WebClient client = new WebClient();
string response = client.DownloadString(url);
// Parse the response and retrieve the current BTC price
dynamic json = Newtonsoft.Json.JsonConvert.DeserializeObject(response);
string price = json.bpi.USD.rate;
// Display the price on the console
Console.WriteLine("The current price of Bitcoin (BTC) is $" + price);
}
}
}
Note: This example uses an API provided by CoinDesk to retrieve the latest BTC price. You may need to install the Newtonsoft.Json NuGet package in order to use the Newtonsoft.Json.JsonConvert.DeserializeObject method.