© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
6 replies
FirstGearGames

Multiple types in a params without casting?

Feel like I'm hoping for an unrealistic expectation, but is it possible to have multiple types in a params without casting to avoid GC?

eg...
        public void DoSomething(params object[] objs)
        {
            for (int i = 0; i < objs.Length; i++)
            {
                if (i % 2 == 0)
                    Debug.Log((int)objs[i]);
                else
                    Debug.Log((string)objs[i]);
            }
        }
        public void DoSomething(params object[] objs)
        {
            for (int i = 0; i < objs.Length; i++)
            {
                if (i % 2 == 0)
                    Debug.Log((int)objs[i]);
                else
                    Debug.Log((string)objs[i]);
            }
        }
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

Casting types inline
C#CC# / help
2y ago
Generics without Casting
C#CC# / help
3y ago
Swagger multiple error types
C#CC# / help
4y ago