I need to publish page B on publish of page A. How can it be done in SDL Tridion 2011 SP1 ? Can it be done through C# TBB ? Can somebody please provide the code sample for the same.
Technically it is possible to do this in a Template Building Block, but it makes more sense to solve it via either an event handler (http://sdltridionworld.com/community/2011_extensions/rapideditorialinterface.aspx) or a custom resolver (http://nunolinhares.blogspot.nl/2011/10/tridion-publisher-and-custom-resolvers.html).
The added benefit of a resolver over an event handler is that you are not creating a new publish action, but you are just adding your additional Page to the existing Publish Transaction.
If you want to know more about custom resolvers, try Googling "tridion custom resolver".
You can achieve this via the Event System. Bart's Rapid Editorial Interface extension is open source and has an example that does what you're looking for. Have a look at it here: http://sdltridionworld.com/community/2011_extensions/rapideditorialinterface.aspx