Scribe
Scribe

Gostou? Torne o Scribe ainda melhor deixando uma avaliação

Obter Extensão do Chrome

Navegar

  • Vídeos Populares
  • Vídeos Recentes
  • Todos os Canais

Ferramentas Gratuitas

  • Baixador de Legendas de Vídeo
  • Gerador de Marcadores de Tempo de Vídeo
  • Resumidor de Vídeos
  • Contador de Palavras de Vídeo
  • Analisador de Títulos de Vídeo
  • Busca de Transcrições de Vídeo
  • Análises de Vídeo
  • Criador de Capítulos de Vídeo
  • Gerador de Quiz de Vídeo
  • Chat com Vídeo

Produto

  • Preços
  • Blog
  • Obter Extensão do Chrome

Developers

  • Transcript API
  • API Documentation

Legal

  • Termos
  • Privacidade
  • Suporte
  • Mapa do Site

Direitos Autorais © 2026. Feito com ♥ por Scribe

— Se isso tornou sua vida mais fácil (ou pelo menos um pouco menos caótica), deixe-nos uma avaliação! Prometemos que vai alegrar nosso dia. 😊

Related Videos

Constructors in C#.NET Part 1 | C#.NET Tutorial | Mr. Bangar Raju

Video thumbnail
439.12k2,913 Palavras14m readGrade 18
Compartilhar
Channel
Naresh i Technologies
[Music] welcome to Nares technologist I'm bangar Raju and in this video uh I will demonstrate about Constructors so what is this Constructor see objectoriented programming is all about writing the code inside classes we just going to write the code inside a class and a class is a collect of various members like Fields methods Constructors etc etc and in that one of the most important member that is present in a class is going to be called as a Constructor so what is a Constructor means it is a special method present under a class responsible for initializing
the variables of that class responsible for initializing the variables of that class so it's a special method present under a class responsible for initializing the variables of that class okay and now the main importance of a Constructor is it is responsible to initialize the variables inside your class what is that we'll talk on it just a minute meanwhile if it is a method it requires a name now and remember the name of a Constructor method the name of a Constructor method is exactly the same name of the class in which it was present the name
of a Constructor method is exactly the same name of the class in which it was present so we can't change this thing now so if your class name is test your Constructor name is test if your class name is demo your Constructor name is demo you cannot change it and another important thing is and moreover it's a non value wring method it's a non-value wring method Constructor methods doesn't require written any value that doesn't written any value so just generally methods are two types value wring non value wring but Constructors are purely nonv value wring
they never written any value and next each and every class requires this Constructor if we want to create the instance of that class this is another important Point each and every class requires this Constructor if we want to create the instance of that class if at all we want to create the instance of that particular class make sure your class contains a Constructor if I don't have a Constructor if you don't have a Constructor we cannot create the instance of the class but when I tell this point you'll be having a doubt what is the
doubt earlier you might be writing classes and in the classes you may not Define anything called as Constructor but still you are able to create the instances of those classes something like this you defined a class like this class test in this class I'm declaring a variable called as in I something like this and now let us somewhere I want to create the instance of this class test obj is equals to new test create the instance of the class so is this statement Val valid yes it is valid we can create the instance but what
the last point is telling here each and every class requires this Constructor if we want to create the instance of the class but here we are creating the instance but we don't have anything called as Constructor and if this is valid the last Point what we are talking here doesn't make any sense why without that Constructor we are telling instance cannot be created and here we don't have a Constructor but still we are able to create the instance so this will be a out what everyone will have in the mind so let me clarify that
what is it it's the responsibility of a programmer to define a Constructor under his class it is the responsibility of a programmer to define a Constructor under his class and if he fails to do so on behalf of the programmer on behalf of the programmer an implicit Constructor gets defined in that class by the compiler on behalf of the programmer an implicit Constructor gets defined in that class by the compiler actually we need to do it but we did not do it if you don't do that on behalf of us the compiler will Define an
implicit Constructor into that class so what happens you know this class after compilation this class after compilation will contain one implicit Constructor like this how public test and remember the name is test why the name is test because the Constructor name should exactly be the class name class name is test so the Constructor name is also test and inside this what will be present you know I is equals to Z what is that initializing the variable initializing the variable so why is the variable getting initialized here that is the responsibility of the Constructor that is
the first point we're talking it's a special method present under a class responsible for initializing the variables of that class so if a class variable is initialized implicitly means that is done by a Constructor that is why every variable you declare directly under the class or every field you declare directly under a class has a default value if you don't give all numeric types are initialized with zeros and Boolean types are initialized with false string and object types are initialized with null means see in this I'm also going to declare a string string s did
not initialize bull b did not initialize and now all the things will come here also string s and bulby but remember inside this Con structor all these are initialized s is equals to default value null and B is equals to default value false so like this the initialization is performed for each and every variable that is the role of the Constructor that is why Constructor is very important for us inside a class and if you don't have this Constructor with these variables will not be initialized because without we assigning a value a value coming there
means there's not a magic show so someone has to assign the value here so who is going to do that the Constructor will do that and this Constructor is not defined by aember we did not Define The Constructor who defined this Constructor the compiler defined this Constructor for us and we call this as a implicit Constructor that is a Constructor that is implicitly defined and if we Define the same thing that is called as explicit Constructor if at all we are going to Define this Constructor explicitly we call that as a explicit Constructor okay otherwise
every Constructor is going to be an implicit Constructor so you till now you might be defining 100 classes in all the 100 classes you never defined a Constructor but still all those classes contain a Constructor and all those class Constructors are defined by the compiler for us and some few important points to remember here Point number one implicit Constructors implicitly defined Constructors Constructors are also known as default Constructors are also known as default Constructors why actually default Constructor means a Constructor which doesn't take any parameter see already on the top I said a point Constructor
is a special method and why I'm just pointing this right now here is see method because of the method you can pass parameters to Method also there is a chance to pass parameters and if you pass any parameters to the particular thing the Constructor will become parameterized and right now there are no parameters so this is a parameterless Constructor this is going to be a parameterless Constructor so every parameterless Constructor will initialize the variables of the class with default values so that's way implicit Constructors are parameterless and parameterless Constructors are also known as default Constructor
so let me change the definition implicitly defined Constructors are parameterless these Constructors are also known as default constu Constructors implicitly defined defined Constructors are parameterless and these Constructors are also known as default Constructors the first important point if a Constructor is implicitly defined don't forget that is parameterless and if it is parameterless they can Al they can also be called as default Constructors Point number two implicitly defined Constructors are public the constructors which are defined implicitly are public you notice said this class is a normal class here but when I defined the Constructor when I
just said the Constructor gets defined I have mentioned here as a public why because implicitly defined Constructors are public they are going to be public Constructors here okay and another thing we can also Define a Constructor under the class we can also Define a Constructor under the class and if we Define it and if we Define it we can call it as explicit Constructor explicit Constructor and explicit Constructor and an explicit Constructor can be parameterless or parameterized also an explicit Constructor can be parameterless or parameterized but implicit Constructors cannot be parameterized implicit Constructors are parameterless
but explicit Constructors can be parameterless or parameterized also two options are there for us both can be done okay fine let's just take a small example and define a Constructor okay here I've taken a project called as demo project in this I have class called program in this program class I wanted to define or I wanted to just declare a variable in I equals to uh or in simple okay next uh bub bu B there two variables now let me come here create the instance of the class program p is equals to new program and
once after creating the instance of the class console do right line P do I the variable name is i p do I trying to print the I value as well as the B value also so one more time I'm writing P do B console do R line and do remember we did not assign any value for I and B but still when you run the code it prints values you can notice still you can see the values printed over there what are the values zero and F but don't forget we did not assign any value
here we did not assign any value here and that value what has coming over there is a given by is given by The Constructor which Constructor implicit Constructor and we don't require to give that value uh let's just print this message a little bit clear what is it value of I is plus and value of B is plus so it's going to print both the two values for us okay so value of I is zero and the value of B is false it's just going to print the two values for us so that's what even
if we did not assign any values you are able to see the value for I and B how the value came now the value came through the Constructor we did not assign so internally this class contains one implicit Constructor and that implicit Constructor is going to initialize the variables okay so can I define these Constructors explicitly you can Define how can I define a Constructor explicitly if you want to define a Constructor explicitly this is the syntax to define a Constructor modifiers name parameter list and write here so this is the syntax your modifiers name
parameter list and then you're going to write your statements here so let us try defining a Constructor on our own now so right now we used an implicit Constructor here and that implicit Constructor is helping us in creating the instance and initializing the variables and you can Define this Constructors explicitly also how to define let's open the solution Explorer add a new class here add a class I'll name the class as X explicit con demo explicit Constructor demo simply call it as explicit con demo now in this class I want to write a Constructor no
public explicit cond demo so this is an explicit Constructor what I defined inside this class public explicit condo this is an explicit Constructor okay and this Constructor if you don't Define also there'll be but implicit now it is explicit and here I'm writing a simple code console dot right line Constructor is called now static void main create the instance now explicit cond demo obj is equals to new explicit con demo creating the instance now we are creating the instance of the class now okay and afterwards console. rline and remember we are creating an instance and
whenever you create an instance there will be a call to the Constructor there will be a call to the Constructor and I I can prove you this like this you can watch Constructor is called how many times times you create the instance that many number of times the Constructor will be called for you suppose I'm creating three instances obj1 obj2 obj3 and you watch it every time you create the instance it will call the Constructor so if you notice the previous program in the previous program we did not Define any Constructor explicitly so the Constructor
is implicit okay so right now I'm going to create the instance when I create the instance now even though the Constructor is implicit a call to the Constructor will take place so what is going to happen now it is going to call the implicit Constructor now and that implicit Constructor is now going to initialize the variables which variables I and B which zero and false so the point to understand is whenever the instance of a class is created then there is a implicit call to the appropriate Constructor why we are going to make the appropriate
point this instance creation will call the Constructor okay means actually I should not use the word implicit here why I should call explicit only why because we are calling the Constructor explicitly where are we calling Watch program P what is program you can see there it is a class present under the demo project namespace it is a class present under the demo project namespace now come here when I say program and put my mouse here it is not showing you class what is it showing you program. program what is program. program the first program is
a class and the second program is your Constructor means you are calling the Constructor explicitly you are calling the Constructor explicitly we are explicitly making a call to the Constructor and when we call the Constructor the implicit Constructor is called and will initialize the variables and coming here here also the same thing only you notice you notice this is your class name and this is your Constructor name and if you debbag you'll understand much better place a breako here by using F9 so let us place a breakpoint here by using F9 and run the code
watch when you added a breako over there when you added a break point the control will go and stop on that line when the execution is taking place just a second uh the control will come and stop on that particular line when you just over for executing the code now the control stopped on the line now press F1 now if you press F1 see what is going to happen so right now the control is on this line which line explicit con demo obj is equals to if you press F1 you see the control jumping to
the Constructor the control jump to the Constructor now and after the control jump to the Constructor now it is executing the code inside the Constructor and coming back next again you're calling the sorry creating the second instance again goes to Constructor call again executes the logic comes back again third instance going to Constructor executing the logic and coming out of this so like this whenever the instance of any class is created the call is explicitly made to the Constructor here a point will be confusing for you a little bit what is it defining second one
calling what is defining what is calling defining a Constructor means implementing one Constructor in your class so this is called defining this is called defining means we are explicitly writing the code for the appropriate thing that's called defining defining can be two types what implicit or explicit what is that implicit or explicit either you define it otherwise compiler will define it but calling what is calling whenever we the instance we are calling the Constructor calling is explicit you only should call implicit calling will not take place defining will be implicit but calling must be done
explicitly if you don't call the Constructor explicitly that is not going to execute that may be an implicit Constructor or that may be an explicit Constructor but calling should be done explicitly by us if you explicitly call only the Constructor which is defined implicitly or which is defined explicitly will execute so this is the basic information for us about a Constructor okay uh in the next video I will just demonstrate about the various types of Constructors that are present in a class and how to work out with them thank you for watching the video for
more videos please subscribe to our YouTube channel Nares it [Music] h [Music]
Vídeos relacionados
Types of Constructors in C#.NET Part 2 | C#.NET Tutorial | Mr. Bangar Raju
30:24
Types of Constructors in C#.NET Part 2 | C...
Naresh i Technologies
275,346 views
Working with Visual Studio .NET | C#.NET Tutorial | Mr. Bangar Raju
29:58
Working with Visual Studio .NET | C#.NET T...
Naresh i Technologies
569,918 views
10 Essential Constructors in C# Every Developer Should Know
12:52
10 Essential Constructors in C# Every Deve...
Zoran Horvat
9,212 views
BREAKING: Attempted assassination arrests in Israel, police say | LiveNOW from FOX
9:39
BREAKING: Attempted assassination arrests ...
LiveNOW from FOX
310,367 views
Structures in C# | C#.NET Tutorial | Mr. Bangar Raju
29:30
Structures in C# | C#.NET Tutorial | Mr. B...
Naresh i Technologies
81,231 views
C# Tutorial For Beginners - Learn C# Basics in 1 Hour
1:10:32
C# Tutorial For Beginners - Learn C# Basic...
Programming with Mosh
5,104,845 views
Inheritance - Part 1 | C#.NET Tutorial | Mr. Bangar Raju
37:26
Inheritance - Part 1 | C#.NET Tutorial | M...
Naresh i Technologies
262,960 views
Access Specifiers in C#.Net | C#.Net Tutorial | Mr. Bangar Raju
29:05
Access Specifiers in C#.Net | C#.Net Tutor...
Naresh i Technologies
189,113 views
Israel leak was done on purpose, says former US Amb to Poland: ‘Clearly the deep state’
7:57
Israel leak was done on purpose, says form...
Fox Business
20,890 views
Constructors in C#.NET Part 3 | Why Constructors are Needed in our class | Mr. Bangar Raju
17:07
Constructors in C#.NET Part 3 | Why Constr...
Naresh i Technologies
160,380 views
Different kinds of Variables in a class | C#.NET Tutorial
36:02
Different kinds of Variables in a class | ...
Naresh i Technologies
141,762 views
C# Constructors - This is how to use them, and WHY
8:00
C# Constructors - This is how to use them,...
tutorialsEU - C#
7,430 views
Interfaces in C# | Part 1 | C#.NET Tutorial | Mr. Bangar Raju
22:45
Interfaces in C# | Part 1 | C#.NET Tutoria...
Naresh i Technologies
173,245 views
Israel to repel Islamic Republic of Iran; IDF targets Hezbollah’ financial arm TV7 Israel News 22.10
17:57
Israel to repel Islamic Republic of Iran; ...
TV7 Israel News
144,120 views
Constructors Part 4 | Static Constructors vs Non Static Constructor | Mr. Bangar Raju
24:21
Constructors Part 4 | Static Constructors ...
Naresh i Technologies
122,725 views
ISRAEL: "Hundreds of millions in gold" found in Hezbollah bunker
5:08
ISRAEL: "Hundreds of millions in gold" fou...
LiveNOW from FOX
2,103,164 views
C# Constructors Tutorial | Mosh
23:24
C# Constructors Tutorial | Mosh
Programming with Mosh
237,412 views
Israel Arrests Spies Working for Iran: Foils Assassination Plot | Vantage with Palki Sharma
1:02:34
Israel Arrests Spies Working for Iran: Foi...
Firstpost
134,982 views
Introduction to LINQ in C# | LINQ (Language Integrated Quer) | C#.NET Tutorial | Mr. Bangar Raju
24:45
Introduction to LINQ in C# | LINQ (Languag...
Naresh i Technologies
150,192 views