Bin vs Obj Folder in C# | C# Interview Questions | Csharp Interview Questions and Answers

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this video we will try to understand what is the importance of this bin folder and obj folder in shisha project in shisha compiling so first let me make a statement here in both of these folders we have compiled code so in other words you know when you write any code in your shape language and when you hit compile both of these folders have you know the DLLs or the compiled code so if you see in the in this bin folder also we have compiled code in the obj folder also we have compiled code but the question here which comes is that we have only one compiled code right so why do we need two folders why can't we just have one folder and in that one folder why don't we have the compiled code we have two folders because the compilation process goes through two steps compiling and linking you can see that above I have flashed a diagram where I've explained that the process of compiling is divided into two phases one is compiling one is linking so what happens is in compiling every code file is compiled into individual compiled units so let us say that if you have in your project multiple files like file 1 dot CS and file 2 dot CS so every one of these files is compiled into individual units the second process what happens is these compiled code files which are compiled individually is later linked into a single assembly which can be a dll which can be an exe depending on what project type you have selected so basically in the compile phase first every code file of your project is compiled individually and then in the link phase all of these compile code files are combined to create a single unit which can be a dll or which can be an exe so whatever happens in the compile phase the individual compile units actually goes in this obj folder and after the link phase the final code the final compilation goes into the bin folder so out of curiosity if we go and see both of these folders for example you can see her this is the bin folder this is the bin folder output let me also show you the folder output for folder output for obj so this is the obj folder output so you can see her at the left hand side I have kept the obj folder output and at the right hand side let me flash the debug folder so you can see her this is the debug folder the bin folder I am sorry and this is the obj folder at the left hand side you can see that there are many files in obj folder you can see this temporary generated file again temporary generated file because over here for every code file which I have in my project he is creating the individual compiled units and if you see at the right hand side you know he has created only one exe and one DLL so basically that intermediate compilation which happens you know where in first you know the individual files are compiled into individual compile units actually going to the obj folder and then later on after the linkage it is either one exe or it's either one DLL a single unit right so you can see here there are many files in the obj folder but there are less number of files in the bin folder but still this does not answer our question why do we need two folders because we can just have one folder in a project that is a bin folder and these intermediate compilation can happen in some temp directory so you can have some see windows temp directory you know where this intermediate compilation happens and in my in my project folder I just have the bin folder the final folder right but if you see at this moment this obj folder is also a part of your project you can see here this is my console application 3 or visual studio and inside this they have put the obj folder so what is the point of having this obj folder inside the project so that means you know that whenever I back up this project whenever I check in this project this obj folder also becomes a part of that checking and backing up right so one of the biggest achievement in or one of the biggest use of having this obj folder is an additional compilation or incremental compilation what does that mean now assume that you have a project and you know project you have you have a lot of solutions you have a lot of projects and in that project you have multiple files like file 1 dot cs5 2 dot cs5 3 5 4 and so on so let us say you first compile initially when you compile it will go ahead and compile everything right and create the final DLL or the exe in the bin folder but now let us say afterwards you just make change in file 3 dot CS so if only v 3 has changed then only file 3 should compile isn't it so that information is only there in the debug folder or in the obj folder I am sorry because in the obj folder we have individual entries of the file compilation so this is the one we folder you know where I can go and check must be the date and timestamp or something and say that ok so if only v 3 has changed then when we file 3 should compile right so because of this obj folder we can have conditional compilation or incremental compilation that means we only compile those files which which have changed and that will make your compilation faster isn't it so let me show you the demo of this conditional compilation how does it how does it work in c-sharp so you can see that i have this solution out here it has class library 1 console application 3 and so on and I have the bin folder and obj folder right so what I will do is first I will go and delete both of these folders so both of these folders are not present so that means and if I go into a build your build solution it will actually go and build the class library also it will go and build the console application 3 because it does not have any history of what has been built and what has not been built but now if I go and do a build again now you can see here if you see the folder it has created the bin folder it has created the obj folder and in the obj folder he has created individual entries of every file right but now if I go and do a build I have not changed anything at this moment so if I do a build solution you can see that he does not build any files can you see that but if I go and change something for example if I go and change here something here like you know just make some enters like this or I delete something all right so I made some change in my file so what it will do is it will go and compare with the obj folder saying that okay is this date and time change or something so if I now do a build you will see that he did not compile class library 3 can you see that he has not compiled class library 3 he has only compiled console app 3 incremental compilation conditional compilation he has only compiled what I have changed so the so that magic is happening because of this obj directory if you see here if I go and again delete it let me do that let me go and delete this if I again to unbelled here you will find that he has compiled console app 3 actually what you know the he has not compiled class library because even the class library has his own obj folder right so let me go and delete the class library obj folder let me go and delete the console app 3 obj folder now if I do a build here you can see that he has compiled both of them so by having the obj folder you would get incremental compilation you would get conditional compilation and your compilation process is faster so if you have a small project if you are doing some sample application practicing something you can happily go and delete this obj folder but if you are working with big projects you know where you come every morning and you do compilation you don't want to compile from the start right you just want to compile what has been changed so in case you are working with big projects keep this obj folder it will save you time but in case you are doing some sample applications or if you have any issues you can happily go and delete the obj folder it will recreate it again I hope that you enjoyed this video in this video we were trying to understand what is the difference between the bin folder and the obj folder in sheesha projects thank you very much [Music] [Music]
Info
Channel: Questpond
Views: 19,305
Rating: 4.9126639 out of 5
Keywords: c#, bin vs obj, C# beginners
Id: vjHage_2g4Y
Channel Id: undefined
Length: 8min 46sec (526 seconds)
Published: Fri Jun 08 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.