 Hello guys, Crypto grounds here. Welcome back to another C sharp crash course video. This is episode six And we're going to be doing getter methods as a part of our classes And anyways, if you enjoyed this video make sure you leave a like Subscribe and turn on the bell if you're new. Anyways, let's get on with it So basically I'm going to be explaining how getters work and what's the purpose of them and when you should use them. All right So normally In a class, let's just make a class. Let's make a public class public class a I'm really bad at curly braces. Let's say we have our public class We have a private variable That we don't want to modify outside of our class. So we make this private. All right And as I explained in the last video private can only be accessed If or it can't it can only be accessed inside this class, right? So of course you could do protected right to make it so that you can do that in another class inside your project But however, the most secure way is a private, right? So how we do this is we declare Using the private term. Let's say we want numbers or variable We're gonna call it. Oh, yeah All right, right, right, right So private Number All right, let's say we have a constructor here to define it as a number. We don't want to change that All right, so I'm going to show you how to change that next episode. That's next one So this is actually having to access it without changing this in another class And this is the most secure way possible So what we can do is write a method. Oh, so this is called an accessor the accessor so basically we just put Public again, we want this to be public so we can access this method in another class, right? So we do public Int Get Number and basically what we can do here is return number There we go. Now this can be used in any class That is declared in if we don't want to declare this class a and for example Nate Why don't you just keep All right, sorry, my brother came in again. So let's say we have public class B. We want to not Declare a so well, I mean what we could do in here. So I'll show you the first way So basically we need to make public a Temp, I don't have a variable name Equals new a we don't have any constructor So it's just blank because the default is just gonna be zero. So this is gonna be zero, right? So we don't have any constructor So what we can do here is Call so let's say we have our method. Let's do Public I hate writing this all out, but let's say we have public Also, this is gonna be static. So let's say we have public static a temp and so we're gonna have we're gonna do this public static void Main and in here we do string Array args for arguments and in here what we can do is We can either do temp we can do console dot write line and do temp dot get number and this will write Zero in the console since this is zero. So that is one way Now what we could do here is make this a static class. So we would just have to write the s word here Which s can be static. Okay, so you don't write s, but I don't want to erase everything So I'll just point an arrow. This is static Okay, so what we can do here now is we can use this wherever you want. So let's say she's just a global class Alright, so of course this can still only be accessed in here. So But you have to write static in because this is a static method All right, you can't declare a static variable in a non static method if that makes sense So here we would simply just do a Here we got to do the console dot write line again and here we just do a dot get number I'm just not gonna bit see yeah Just like that All right, that is how you use a getter. So basically in summary is Just a way to access a variable in another class in the most secure way possible Alright That is what a getter is. Thank you guys for watching. I hope you guys enjoyed this video If you have any questions, let me know in the comments below Don't forget to leave a like subscribe to my channel and turn on notifications you guys. Thanks for watching. Have a good one. Peace