Preheat your oven to 350°F (175°C) and grease a 9 x 13-inch baking dish with butter or nonstick spray.
If using frozen corn, thaw completely and drain well. Drain canned corn, if using. Fresh corn should be cut off the cob.
In a large mixing bowl, toss the corn with the flour to coat evenly. This helps thicken the casserole as it bakes.
In a separate medium bowl, whisk together the melted butter, eggs, milk, sugar, salt, and pepper until well combined.
Pour the wet mixture into the corn mixture and stir until fully blended.
Pour the mixture into the prepared baking dish and smooth the top. Bake for 1 hour, or until golden brown and set in the center.
Let the baked corn cool for about 5–10 minutes before serving. Enjoy warm with your favorite main dish!