C# client library
Use our C# client library to integrate News API into your C# application without worrying about what's going on under the hood.
Source: News-API-gh/News-API-csharp
Installation
The C# client library is available on Nuget. You can install it either through the Nuget package management window in Visual Studio by searching for NewsAPI, or by running the following command in the package manager console:
PM> Install-Package NewsAPI
Usage
using NewsAPI;
using NewsAPI.Models;
using NewsAPI.Constants;
using System;
namespace MyApplication
{
class Program
{
static void Main(string[] args)
{
// init with your API key
var newsApiClient = new NewsApiClient("API_KEY");
var articlesResponse = newsApiClient.GetEverything(new EverythingRequest
{
Q = "Apple",
SortBy = SortBys.Popularity,
Language = Languages.EN,
From = new DateTime(2018, 1, 25)
});
if (articlesResponse.Status == Statuses.Ok)
{
// total results found
Console.WriteLine(articlesResponse.TotalResults);
// here's the first 20
foreach (var article in articlesResponse.Articles)
{
// title
Console.WriteLine(article.Title);
// author
Console.WriteLine(article.Author);
// description
Console.WriteLine(article.Description);
// url
Console.WriteLine(article.Url);
// published at
Console.WriteLine(article.PublishedAt);
}
}
Console.ReadLine();
}
}
}