Weapon Switch

I can’t imagine a system to switch between weapons, when i has the first and the second weapon, it was easy, i was using:

if(currentWeapon = "M9") {
     M9.Active = true;
     M4A1.Active = false;
}

else if(currentWeapon = "M4A1") {
     M9.Active = false;
     M4A1.Active = true;
}

but now i have more than two weapons, and i want the primary and the secondary weapon
and if i use that script for 20 weapons for e.g the script would have 9123123 lines of code, exist a simply way to do that? i dont want code i want explaination, using csharp. someone?

you could make a gun controller script,
store your guns into an array,use a variable to store the current gun and just switch between them when you press the respective button.

just an ideea.