© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
29 replies
mrdudebro1

Branching if statements

so. i have some data in a database that needs to be assigned data based on an id.
I have a database full of items, and each item has attributes. lets say they are tools. the id could be
HAMMERSTEEL.10
HAMMERSTEEL.10
or
HAMMERIRON12.12
HAMMERIRON12.12
. the first one means it's a 10" long steel hammer with a standard head size and the second one is a 12" long iron hammer with a 12mm head or something of that nature. i have at least four different base types
HAMMER
HAMMER
AXE
AXE
SCREWDRIVER
SCREWDRIVER
. I need to assign attributes in a new table based on the item id's. what i already have is a database filled with what i want the data to look like. i'll read in hte item id
HAMMERSTEEL.10
HAMMERSTEEL.10
and then i'll asign the attributes in another table.

for example:

if(itemId.matches `hammerregex`) {
//  build an update statement in sql that will assign the appropriate values
}

if(itemId.matches `axeregex) {
  //build an update statemet in sql that will assign appropriate axe values
}
if(itemId.matches `hammerregex`) {
//  build an update statement in sql that will assign the appropriate values
}

if(itemId.matches `axeregex) {
  //build an update statemet in sql that will assign appropriate axe values
}


I want to cut down on the amount of branching if statements. any suggestions?
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

If statements
C#CC# / help
3y ago
✅ multiple if statements
C#CC# / help
3y ago
Confused about if statements
C#CC# / help
2y ago