c#->vb.net

  • VB.NET
  • .NET (FX) 4.5–4.8

Es gibt 5 Antworten in diesem Thema. Der letzte Beitrag () ist von Marcus Gräfe.

    Hallo bin noch neu mit Programmieren =)

    ich krieg das einfach nicht überstezt =( mag mir wer helfen?


    C#-Quellcode

    1. using System;
    2. using System.Threading.Tasks;
    3. using PUBGSharp.Data;
    4. using PUBGSharp.Exceptions;
    5. using PUBGSharp.Helpers;
    6. namespace PUBGSharp.Examples
    7. {
    8. internal class Program
    9. {
    10. private Program()
    11. {
    12. }
    13. public static void Main(string[] args) => new Program().MainAsync().GetAwaiter().GetResult();
    14. private async Task MainAsync()
    15. {
    16. // Create client and send a stats request You can either use the "using" keyword or
    17. // dispose the PUBGStatsClient manually with the Dispose method.
    18. using (var statsClient = new PUBGStatsClient("api-key-here"))
    19. {
    20. var stats = await statsClient.GetPlayerStatsAsync("Mithrain").ConfigureAwait(false);
    21. // Print out player name and date the stats were last updated at.
    22. Console.WriteLine($"{stats.PlayerName}, last updated at: {stats.LastUpdated}");
    23. try
    24. {
    25. // Print out amount of players KDR (Stats.KDR) in DUO mode (Mode.Duo) in ALL
    26. // regions (Region.AGG) in SEASON 1 (Seasons.EASeason1).
    27. var kdr = stats.Stats.Find(x => x.Mode == Mode.Duo && x.Region == Region.AGG && x.Season == Seasons.EASeason1).Stats.Find(x => x.Stat == Stats.KDR).Value;
    28. Console.WriteLine($"Duo KDR: {kdr}");
    29. // Print out amount of headshots kills in SOLO mode in NA region in SEASON 2.
    30. var headshotKills = stats.Stats.Find(x => x.Mode == Mode.Solo && x.Region == Region.NA && x.Season == Seasons.EASeason2).Stats.Find(x => x.Stat == Stats.HeadshotKills);
    31. // You can also display the stats by using .ToString() on the stat object, e.g:
    32. Console.WriteLine(headshotKills.ToString());
    33. // Print out amount of kills in the last season player has played in:
    34. var latestSeasonSoloStats = stats.Stats.FindLast(x => x.Mode == Mode.Solo);
    35. var kills = latestSeasonSoloStats.Stats.Find(x => x.Stat == Stats.Kills);
    36. Console.WriteLine($"Season: {latestSeasonSoloStats.Season}, kills: {kills.Value}");
    37. }
    38. /* IMPORTANT STUFF ABOUT EXCEPTIONS:
    39. The LINQ and other selector methods (e.g. .Find) will throw NullReferenceException in case the stats don't exist.
    40. So if player has no stats in specified region or game mode, it will throw NullReferenceException.
    41. For example, if you only have played in Europe and try to look up your stats in the Asia server, instead of showing 0's everywhere it throws this. */
    42. catch (PUBGSharpException ex)
    43. {
    44. Console.WriteLine($"Could not retrieve stats for {stats.PlayerName}, error: {ex.Message}");
    45. }
    46. catch (NullReferenceException)
    47. {
    48. Console.WriteLine($"Could not retrieve stats for {stats.PlayerName}.");
    49. Console.WriteLine("The player might not exist or have stats in the specified mode or region.");
    50. }
    51. /* Outputs:
    52. Mithrain, last updated at: 2017-09-07T19:53:40.3611629Z
    53. Duo KDR: 2.87
    54. Stat: Headshot Kills, value: 69, Rank: #
    55. Season: 2017-pre4, kills: 32
    56. */
    57. }
    58. await Task.Delay(-1);
    59. }
    60. }
    61. }




    MfG DeniD
    Willkommen im Forum,

    wenn du wirklich neu bist verstehe ich nicht warum du unbedingt den Code von anderen Leuten C&P willst, wenn es dir überhaupt nicht beim Programmieren lernen hilft. Wenn du auf dem Stand bleiben willst, dann nutze doch einfach einen der zahlreichen kostenlosen Converter die es gibt. Glaubst doch nicht wirklich, dass dir hier jemand 60 Zeilen Code übersetzt, die du mit ein wenig Übung auch selbst übersetzen könntest.

    Seit wann kommt bei den Online Convertern Müll raus ? 8|
    Desweiteren ist der Code komplett Kommentiert.

    Es sollte dir ein leichtes sein mit ein wenig Grundlagen des Frameworks sogar selbst zu übersetzten.
    Du solltest auch nicht einfach dinge aus dem Internet kopieren bei dir einfügen und fertig,
    du lernst so absolut null. Ich denke hier wird dir auch keiner einfach so diesen Code übersetzten
    (zumal es genügend online Konverter gibt die das eh schon können) ohne das du irgendwas dazu beigetragen hast.
    Grüße , xChRoNiKx

    Nützliche Links:
    Visual Studio Empfohlene Einstellungen | Try-Catch heißes Eisen