Western Digital Corp. agreed to buy SanDisk Corp. for about $19 billion (¥2.26 trillion), gaining access to a supply of semiconductors that are at the heart of a fast-growing type of computer storage.