Linear codes with complementary duals (LCD) are linear codes whose intersection with their dual are trivial. When they are binary, they play an important role in armoring implementations against side-channel attacks and fault injection attacks. Nonbinary LCD codes in characteristic 2 can be transformed into binary LCD codes by expansion. In this paper, we introduce a general construction of LCD codes from any linear codes. Further, we show that any linear code over Fq (q>3) is equivalent to a Euclidean LCD code and any linear code over Fq2 (q>2) is equivalent to a Hermitian LCD code. Consequently an [n,k,d]-linear Euclidean LCD code over Fq with q>3 exists if there is an [n,k,d]-linear code over Fq and an [n,k,d]-linear Hermitian LCD code over Fq2 with q>2 exists if there is an [n,k,d]-linear code over Fq2. Hence, when q>3 (resp. q>2) q-ary Euclidean (resp. q2-ary Hermitian) LCD codes possess the same asymptotical bound as q-ary linear codes (resp. q2-ary linear codes). This gives a direct proof that every triple of parameters [n,k,d] which is attainable by linear codes over Fq with q>3 (resp. over Fq2 with q>2) is attainable by Euclidean LCD codes (resp. by Hermitian LCD codes). In particular there exist families of q-ary Euclidean LCD codes (q>3) and q2-ary Hermitian LCD codes (q>2) exceeding the asymptotical Gilbert-Varshamov bound. Further, we give a second proof of these results using the theory of Gröbner bases. Finally, we present a new approach of constructing LCD codes by extending linear codes.