+ 2

c# using httpclient

using System; using System.Net.Http; class Program { public static void Main (string[] args) { string GetRandomWord() { HttpClient wc = new HttpClient(); string wordlist = wc.DownLoadString("https://raw.githubusercontent.com/imsky/wordlists/master/nouns/food.txt"); string[] words = wordlist.Split('\n'); Random rnd = new Random(); return words[rnd.Next(0, words.Length - 1)]; } } } the code is supposed to run a random word selected in the link however it's not running I believe it has something to do with httpclient.

24th Feb 2022, 4:43 PM
Johnny Meyer
Johnny Meyer - avatar
1 Odpowiedź
+ 2
The code you have copied in here does not run. GetRandomWord is not called as a function. Unfortunately the sololearn playground does not allow the use of System.Net.Http. So we can't use HttpClient in the playground. When I test this code in my visual studio. It gave me the following error HTTPClient does not contain a definition for download string. Download string is part of WebClient https://code.sololearn.com/cKejPNERssf5/?ref=app
24th Feb 2022, 7:22 PM
sneeze
sneeze - avatar