Two problems: the ocean and the Hudson river. The sea approaches NYC from two directions. To the south is the passage between Long Island and Staten Island, and to the east is the passage between the mainland and Long Island.
If your goal is to protect all five boroughs of NYC, you have to protect Brooklyn, which faces the open sea directly. So a huge seawall south of of Brooklyn, crossing over to Sandy Hook. That looks to be closer to 10 km straight across.
The east is also tricky, because the Bronx reaches so far north and east. Your best bet is probably a dam at Sands Point, but it will have to be a good 4 km long. That should be fun.
Finally there is the Hudson river, which flows north to south. You are going to have to divert that somewhere, or it will just pool up in New York harbor until it finds a way to the sea. A Yonkers-New Rochelle canal perhaps?
If this is your plan, you will have the gratitude of an entire generation of civil engineers, construction workers, and financiers. Your taxpayers may be less enthusiastic.