Not exactly, you have to download a virus, they don't usually just plop on your computer. That's why they aren't illegal. Downloading is something you do by choice.
Viruses are hidden in other programs and things like that, so the people that get them don't know they're there when they download something. If you write, hide, and distribute a virus, you are breaking a law.
If I use your example, I could say "Oh if you go walk down that dark alley, there's a chance you could get murdered."
If you walk down it anyway, and do get murdered, the guy who murdered you won't get away with it just because you knew the risk involved.
what they do isn't usually illegal.
And that's just plain wrong.