Speaking at a school in London, Sir Ian McKellen said that he thinks hiding his sexuality for years was pivotal in perfecting his acting skills.

The openly gay actor, of the X-Men and Lord of the Rings trilogies, said “pretending to be someone else”, played in important role in honing his skills as a world-famous actor, the Telegraph reported.

Sir Ian, 73, spoke of the differences between when he was starting out as an actor, and now:

“There was no Graham Norton on the television at that time, no gay MPs, no-one talking about gay rights on the radio. So I dealt with it my trying to cut that part of myself off, to hide myself, to choke a part of me.

“When you are made to feel you are so wrong for being who you are, that’s what you do.

“I think that’s why so many great British actors are gay – we spent so long pretending to be straight, to be someone else, that eventually we became very good at it.”

Sir McKellen was speaking at Acland Burleigh school in north London as part of a national tour with Stonewall, the gay rights charity, in a campaign aimed at tackling homophobic bullying.

He told pupils he “wished that every child, every teacher, every person in this room can be free to be who they are, whatever their sexual orientation”.

He came out in his 40s, during a BBC radio interview in 1988 around the time of section 28 of the Local Government Act, which banned the “promotion” of homosexuality by local authorities. After coming out, Sir Ian said:

“I learned that coming out was crucial to self-esteem. And I accepted the argument that people who thrived in society’s mainstream and had access to the media could, by telling the truth, help others in the backwaters whose views were never sought and whom society either ignored or abused.

“An actor is more protected than most. These days I daily make this point to anyone who will listen because, when I eventually accepted it on the BBC, it changed my life forever for the better.”

In January this year, Sir Ian said he had “no doubt” the complexities and plot devices of Shakespeare’s work mean the playwright was gay.