Will a 300zx ecu work in a 240sx?

Definitely not. Computers may look the same on the outside, but get a wiring diagram and you'll see that the terminals are different. You'll lose certain sensor connections, or maybe even fuel injector connection, not to mention other things causing your check engine light to come on. Plus it is against Federal Laws which prohibit this, and Smog Garages will not test it