© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
28 replies
Brutal_Boost

Is there a way to get rid of the Task type on an object?

I am building my first full stack app where I am building a .NET core website and an API for it to make queries to the database.



I am having trouble converting the API returns into the proper formats that I need for the front end. I can't figure out how to convert Task<IEnumerable<Appetizer>> into List<Appetizer>. I've tried a few different solutions and no luck so far.

public class AppetizerService
{
        private List<Appetizer> appetizers = new List<Appetizer>();
    
        public static string BaseAddress = "http://127.0.0.1:5000";
        static readonly string Url = $"{BaseAddress}/";
    
        static HttpClient client = new HttpClient();
    
        public async Task InitializeAppetizerServiceAsync()
        {
                    this.appetizers =  getAppetizers();
            await Task.Delay(100);
        }
    
        public List<Appetizer> getAppetizers()
        {
            this.appetizers = getAllAppsFromApi();
    
            return this.appetizers;
        }


        public static async Task<IEnumerable<Appetizer>> getAllAppsFromApi()
        {
    
            string result = await client.GetStringAsync($"{Url}api/all_apps");

            var temp = JsonConvert.DeserializeObject<List<Appetizer>>(result);

            return temp;

        }
}
public class AppetizerService
{
        private List<Appetizer> appetizers = new List<Appetizer>();
    
        public static string BaseAddress = "http://127.0.0.1:5000";
        static readonly string Url = $"{BaseAddress}/";
    
        static HttpClient client = new HttpClient();
    
        public async Task InitializeAppetizerServiceAsync()
        {
                    this.appetizers =  getAppetizers();
            await Task.Delay(100);
        }
    
        public List<Appetizer> getAppetizers()
        {
            this.appetizers = getAllAppsFromApi();
    
            return this.appetizers;
        }


        public static async Task<IEnumerable<Appetizer>> getAllAppsFromApi()
        {
    
            string result = await client.GetStringAsync($"{Url}api/all_apps");

            var temp = JsonConvert.DeserializeObject<List<Appetizer>>(result);

            return temp;

        }
}
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ is there any way to cast Task into Task<object>?
C#CC# / help
3y ago
✅ is there a way to get the method name from Task?
C#CC# / help
3y ago
❔ Is there a way to name an object with an input?
C#CC# / help
3y ago
Is there a good way to use a object from Type Type in a generic method?
C#CC# / help
4y ago