Shakespeare's comedy Twelfth Night follows the outline of Elizabethan comedy as it has the elements of mistaken identity, separated twins, and gender-crossing disguise. With these elements comes the dramatic irony that contributes to the comedic effect of the play.
1. Perhaps the most salient example of dramatic irony is the disguise of Viola, who is saved after being shipwrecked by a captain who puts in to shore on Illyria. After learning that the captain knows the Duke of Illyria, Viola asks him to disguise her as a eunich so that she may work in his service. In this disguise, that only the audience is privy to, Viola is better able to perceive the true nature of the characters as they confide in Cesario, her male disguise. When she goes to work for the Duke, he has Cesario go to Olivia's house to plead his love for him. However, Viola who is actually in love with the Duke, says in an aside after telling the Duke,"Ill do my best to woo your lady,"
Yet a barful strife!
Whoe'er I woo, myself would be his wife. (1.5.41-42)
The original love connection of the Duke has been skewered by the end of this scene since there are two twists to the plot: Viola states her attraction to the Duke Orsino; Olivia reveals a liking for Cesario/Viola. The effect of this dramatic irony is to demonstrate the subjectivity of love. For, when a person sees someone with whom he/she falls in love, this love is felt in the person who does the loving of another. And, a person cannot be made to feel love simply by the attraction of the other for him/her.
2. Another example of dramatic irony occurs when the Puritan Malvolio mistakenly believes that Olivia is in love with him after he receives a forged letter actually written by Maria that he believes is from Olivia. In Act I, Scene 5, the letter to Malvolio, supposedly written by Olivia, he is instructed to wear yellow hose and crossed garters. When he approaches Olivia, she is astounded by his attire and smiles. This scene about the "full of water Malvolio" affords Shakespeare the opportunity to assail the hypocrisy and judgmental nature of Malvolio, a hypocrisy not untypical of the unpopular Anabaptists.
3. In Act IV, Sebastian and Olivia are brought together. Since Olivia has already spoken to Cesario about her love, she assumes again that she is speaking to Cesario when it is Sebastian that she addresses. Even though Sebastian is confused by her declaration of love, he enjoys the sentiment, and takes part in the illusion:
What relish is in this?
Or I am mad, or else this is a dream.
Let fancy still my sense in Lethe steep;
If it be thus to dream, still let me sleep! (4.1.60-3-63)
The irony here produces the result of enlightening the audience to the fact that some lovers delight in the illusions of love and often are satisfied with being the object of someone's else love.