1 00:00:06,450 --> 00:00:06,910 Hello. 2 00:00:07,680 --> 00:00:14,580 In this video, we're going to talk about Question 15, what is the difference between type of and the 3 00:00:14,580 --> 00:00:15,210 type? 4 00:00:15,780 --> 00:00:22,260 Both type of keyword and the type of method are used to get the information about some type. 5 00:00:22,620 --> 00:00:28,890 The differences between them are that the type of takes, the name of the type we want to inspect. 6 00:00:29,160 --> 00:00:34,710 So we must know the type before type of is resolved at compile time. 7 00:00:35,370 --> 00:00:39,690 Good type is a method that must be executed on an object. 8 00:00:40,020 --> 00:00:43,050 Because of that, it is resolved at one time. 9 00:00:43,650 --> 00:00:51,270 This method comes from the system object based class, so it is available in any object in C-sharp both 10 00:00:51,270 --> 00:00:59,640 type of and get type method return an object of the type class this object hosts or information about 11 00:00:59,640 --> 00:01:00,330 the type. 12 00:01:00,510 --> 00:01:04,530 For example, it contains the type name list of the constructors. 13 00:01:04,710 --> 00:01:08,190 The base type implemented interfaces, et cetera. 14 00:01:08,640 --> 00:01:09,360 All right. 15 00:01:09,720 --> 00:01:12,510 Let's see type of and grid type in practice. 16 00:01:13,020 --> 00:01:19,050 If I know of the type already and they only wanted to get the type object for some reason, I can use 17 00:01:19,200 --> 00:01:20,340 the type of keyword. 18 00:01:37,830 --> 00:01:45,690 Here are used the type of was the base type, but here I executed the good type method on an object. 19 00:01:47,400 --> 00:01:54,660 In both cases, the result is the type object containing full information about the type called base. 20 00:01:55,830 --> 00:02:01,980 We don't always know the type at computation time, so we can't always use the type of keyword. 21 00:02:02,280 --> 00:02:04,080 Let's consider this method. 22 00:02:15,490 --> 00:02:20,130 This object can be anything, and it will only be known at random. 23 00:02:20,170 --> 00:02:20,720 What it is? 24 00:02:20,740 --> 00:02:21,430 Exactly. 25 00:02:21,760 --> 00:02:27,340 That's why I can't use type of here because I wouldn't know what to pass as the parameter. 26 00:02:27,670 --> 00:02:30,070 I must use the gift type formatted. 27 00:02:30,550 --> 00:02:33,790 Let's see the print type named method in action. 28 00:02:41,960 --> 00:02:45,860 As you can see, it's printer, the actual type of those objects. 29 00:02:47,510 --> 00:02:53,540 The important thing to understand is that grid type always returns the actual type of an object. 30 00:02:53,810 --> 00:02:54,980 Let's see an example. 31 00:03:03,460 --> 00:03:11,380 Even if this variable is of type base, I assigned an object of type direct to it, it is possible because 32 00:03:11,380 --> 00:03:19,030 derived inherits from base, the good type method printer, the actual type, we actually have seen 33 00:03:19,030 --> 00:03:26,470 this before in the print type method, even if it took a parameter of system, object type, it printer, 34 00:03:26,480 --> 00:03:28,870 the actual type of the given object. 35 00:03:29,320 --> 00:03:36,190 Remember, does the get type method belongs to the system object type so it can be called on an object 36 00:03:36,190 --> 00:03:37,090 in C-sharp? 37 00:03:37,660 --> 00:03:45,220 Let's summarize both type of and forget that method return a type object which holds the information 38 00:03:45,220 --> 00:03:51,250 about the type type of things, the name of a type, and it gets resolved at compilation time. 39 00:03:51,730 --> 00:03:56,920 The type method is called upon an object, so it is resolved at random. 40 00:03:57,400 --> 00:04:03,910 Both type of and the good type method are parts of the reflection mechanism, which we learn about in 41 00:04:03,910 --> 00:04:04,900 the next lecture. 42 00:04:05,380 --> 00:04:11,250 If this topic is touched during the interview, you can be asked What is the purpose of the gut type 43 00:04:11,270 --> 00:04:11,920 method? 44 00:04:12,340 --> 00:04:18,910 This method requires the type object which holds or information about the type of an object it was called 45 00:04:18,910 --> 00:04:19,270 on. 46 00:04:19,540 --> 00:04:26,440 The type object contains Phoenix like type name, list of constructors attributes, the best type, 47 00:04:26,440 --> 00:04:30,310 etc. One is the goods type method defined. 48 00:04:30,790 --> 00:04:35,980 It is defined in the system object type, which is a base type for all types in C sharp. 49 00:04:36,220 --> 00:04:40,570 This is why we can call the get type method on objects of a type. 50 00:04:41,290 --> 00:04:46,960 All right, thanks for watching, and I'll see you in the next lecture where we will discuss reflection.