Do you copy and paste code from online websites such as C# Corner or Microsoft Docs? Do you find code snippets on online forums such as StackOverflow and copy and paste into your project? Do you download open-source projects and libraries and use them in your projects? Do you use Github or Nuget package for your projects?
This all is copying and pasting code. This means you have copied someone else’s work in your project. But nothing to worry about. You’re not alone. According to a poll by C# Corner, 75% of coders have copied and pasted code in their projects.

Many open source believers love to share their code. I started C# Corner in the year 2000 just to share my code with the world. I shared my first open-source project in 1999 written on the Mindcracker.com website in C++.
Is copying and pasting someone else’s code legal? Or ethical? Or even allowed?
The brief answer is, YES. BUT there is a catch. It’s not as simple as it seems. If you did not pay attention to the licensing, you may get in trouble. As a matter of fact, many companies do not allow their coders to copy and paste public code. If you work for a large company, you may want to check with your company’s best practices. This is exactly what I will discuss in this article. I will clearly explain the best practices of copying and pasting someone else’s code in your projects and also not get in trouble.
Note: Most of the code available on C# Corner is free to copy and use anyway you see it fit unless otherwise author has some notes in their code. Let me be clear. If you just copy some code snippet from a website like C# Corner, you're free to learn, make minor tweaks to the code, and use in your projects. If you're copying large files and projects, make sure you read licensing topic below in this article.
First may not be the best.
When you are looking for a code snippet and Google it, you get so many search results. The first result may not be the best result. You must compare a few results and see which one is the best option for you. Before you copy and paste the code, look for few important things such as when was the code published, what version of the product used, who the creators is, are the standards used and met in the code, and read if there are any comments and remarks.
I know I published an article on C# Corner with code snippet in it in 2001 that was written for .NET 1.1 and that article still comes in top Google searches.
Read copyrights and ownership.
Just because someone has written a blog or shared a code snippet or even uploaded a project on Github or other open source platforms doesn’t mean you can copy code and do whatever you want. While most of the open source licenses allow you to copy and paste code in your own projects the way you like, but some of them come with some restrictions.
A whopping 63% of developers don’t read or understand that licensing is a major issue when it comes to copy and paste publicly available code in their projects.

The following is a list of some of the most popular open source licenses.
- Apache License 2.0
- BSD 3-Clause/BSD 2-Clause
- GNU General Public License (GPL)
- GNU Library or "Lesser" General Public License (LGPL)
- MIT license
- Mozilla Public License 2.0
- Common Development and Distribution License
- Eclipse Public License version 2.0
While they all allow you to use source code for private and commercial use, most of them require you to include a copy of the license and copyright notice with the material used. This is very important.
So, before you copy and paste a code snippet, large code files, or open source projects, make sure to read the licensing and copyright details. If a website does not have any licensing and copyright, I highly suggest not to use that code in your projects.
Check versions and date of release.
Software products change each year. If you work with a programming language such as C#, it is changing every year. There is a new product release with new and improved features
So, before you copy and paste code, don’t forget to look for the version of the product and its published date
Check author’s credibility.
This is probably the most important factor when copying code from a public website. There are millions of software developers who publish and share their code online and many of these developers are students and inexperienced developers. It’s not that they cannot write good quality code but it's possible that they may not understand the code quality, speed, and performance. Also, many websites write generic and basic code that is not written by expert developers. Some websites that are great in SEO also have very old and obsolete content that probably should not be referenced today.
The code published by a Program Manager at Microsoft or from a team member of C# language or React Dev team is more likely to have high quality and optimized than a young student who has just started learning the language.
Scan for vulnerabilities and performance.
There are several tools out there that can look a project or code for vulnerabilities. While, in most cases, you may not need it but most companies have tools to scan code from vulnerabilities and security holes. If you’re downloading code from a public repo, don’t forget to read the notes, unfinished features, bugs, issues, and users’ comments. Many open source projects have known issues.
Understand exactly how it works.
After agreeing with all the above, you’ve decided to use a piece of code in your project. Some developers directly copy and paste code without understanding it as long as it works.
You as a good developer must understand what exactly the code does and how it works.
Rewrite it in your own language.
Now, you know how a piece of code works. The next thing I highly recommend is, rewrite it in your own language and syntaxes. If there can be any improvements made, make them. If code can be optimized, optimize it. But when you’re done with the final code, nobody should be able to say, this is the exact code copied from somewhere else.


Jaydeep PatilPosted Oct 6, 2022, 6:19 PM
Very helpful information
Sagar LadPosted Oct 8, 2021, 2:53 PM
Informative Article
Arnab MukherjeePosted Oct 8, 2021, 5:40 AM
Very informative. Thanks for sharing this.
Rijwan AnsariPosted Oct 5, 2021, 10:18 AM
Thank you Mahesh Chand sir for such important information. I will use the above article for my development team KT. :)
Md SarfarajPosted Oct 5, 2021, 7:34 AM
Thank you Mahesh sir for sharing this article. before I was copy code and doesn't read the license part, but from now I will read.
Rikam PalkarPosted Oct 4, 2021, 11:35 AM
Bravo. Licensing part was crucial to understand. Thanks Mahesh Chand