Viola finds herself in a difficult position at the beginning of Shakespeare's Twelfth Night. She is shipwrecked in an unknown place among unknown people, and as a young woman, she is especially vulnerable. So Viola cleverly decides to disguise herself as the young man Cesario and go to work for Duke Orsino. She doesn't really have any other choice, for she thinks that she is all alone in the world.
This is why Viola may be called both the heroine and hero of Twelfth Night. She is the heroine because she is a brave, smart, resourceful young woman who is doing her best to make her way in a potentially hostile world. She controls herself well even when she is in disguise, navigating both her own growing love for the Duke and Olivia's immediate infatuation with "Cesario." She tries to avoid trouble the best she can, remain in character, and match wits with everyone she meets; and for the most part, she succeeds, except perhaps in avoiding trouble (although when she fails to avoid it, she isn't at fault).
Viola may also be called the hero of Twelfth Night in her alter ego Cesario. "He" proves to be a young man of virtue, kindly yet firmly rejecting Olivia's advances and practically refusing the silly aggression of Sir Toby and Sir Andrew. Cesario strives to walk to middle way in his dealings and earn the respect of people without losing self-respect.
Of course, Cesario is Viola herself, as is finally revealed to all at the end of the play. Viola wins the Duke's heart at last, and Olivia is happy with Viola's brother, Sebastian, who did not perish in the shipwreck after all. Viola's choices and actions have brought about a happy ending.