this post was submitted on 11 Jul 2024
5 points (100.0% liked)
C Sharp
1526 readers
2 users here now
A community about the C# programming language
Getting started
Useful resources
- C# documentation
- C# Language Reference
- C# Programming Guide
- C# Coding Conventions
- .NET Framework Reference Source Code
IDEs and code editors
- Visual Studio (Windows/Mac)
- Rider (Windows/Mac/Linux)
- Visual Studio Code (Windows/Mac/Linux)
Tools
Rules
- Rule 1: Follow Lemmy rules
- Rule 2: Be excellent to each other, no hostility towards users for any reason
- Rule 3: No spam of tools/companies/advertisements
Related communities
founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
You could still do it that way with a switch. Only the case part needs to be constant...
` switch (field.GetType().ToString()) {
case "Int": Method((int)x)...
case "NullInt": Method((int?)x)...
case "Long": Method((long)x)... `
Been a while since I last did this though - you may need to do string caseType=field.GetType().ToString() first, then do switch(caseType). I think from memory you can do it the other way though.
P.S. I clicked on "code" (which just starts/ends with an apostrophe), but it doesn't want to display as code - I don't know why