background top icon
background center wave icon
background filled rhombus icon
background two lines icon
background stroke rhombus icon

Download "Обобщения или шаблоны (Generic) в C# - Учим Шарп #12"

input logo icon
Video tags
|

Video tags

обобщения c#
обобщения
дженерики c#
обобщение c#
универсальный тип c#
шаблоны c#
generics c#
generic c#
generic
generics
шаблоны
обобщение
дженерики
универсальный тип
программирование c#
программист c#
программирование
программист
c# программирование
c#
с#
.net
c sharp
csharp
visual studio c#
it
visual c#
dotnet
си шарп
c# уроки
программирование с нуля
уроки c#
c# для начинающих
c# курс
c# уроки для начинающих
code blog
шванов вадим
учим шарп
codeblog
ityoutubersru
разработка
Subtitles
|

Subtitles

subtitles menu arrow
  • ruRussian
Download
00:00:11
good evening,
00:00:13
I hope you
00:00:15
can see and hear if this is the case, please
00:00:17
write in the comments so that I know that
00:00:19
everything is fine and we can calmly
00:00:22
study the Sysharp language, and
00:00:26
accordingly, today we have a rather
00:00:28
important interesting topic - the so-called
00:00:32
generics
00:00:34
or templates or universal
00:00:38
[music]
00:00:42
universal type and or damn, whatever they are
00:00:46
called generalization, that is, a
00:00:49
bunch of names are all essentially
00:00:52
synonyms
00:00:53
hi max, yes I see that everything is fine,
00:00:57
excellent, but accordingly the name is
00:01:00
used a lot often an
00:01:05
important question is often asked of the same
00:01:08
guys for interviews, that is,
00:01:11
if I apologize if you are planning to get a
00:01:15
job, with a high degree of
00:01:18
probability you
00:01:20
will be asked a question on this topic, and this
00:01:22
is considered a question, well, let's say, not quite
00:01:24
basic,
00:01:27
if a person seems to understand something,
00:01:31
you can already ask project origin and rivers,
00:01:33
but if there is nothing understands something about
00:01:36
some kind of iv and they ask about
00:01:41
the reference significant you, in this regard,
00:01:43
we study the templates accordingly,
00:01:51
first, as usual, we’ll talk a little about the
00:01:54
logic about the meaning, why is this necessary,
00:01:59
who is to blame and what to do, and after that,
00:02:03
accordingly, as usual, we’ll
00:02:06
look at it in practice Let's open the
00:02:07
development environment and write a little
00:02:11
code there, the code that will be used for classes will also be
00:02:15
posted on git hop, that is, if you wish,
00:02:17
you can go and look there at any time,
00:02:21
download and modify it for yourself, although there
00:02:24
will be such purely theoretical
00:02:29
examples without real analysis in the
00:02:31
future in the future. I’m planning on
00:02:34
devoting a
00:02:36
course to the full development of a project from 0
00:02:41
from scratch to complete, so coming up with ideas and
00:02:45
writing some kind of plan there,
00:02:48
let’s say until the final result, but
00:02:53
in order to start this plan,
00:02:56
we need to start by
00:03:02
just studying the basic the syntax of the language
00:03:05
accordingly already knows the syntax it
00:03:09
will already be possible to implement something so
00:03:13
accordingly before starting I must
00:03:16
remind you that as part of this for this
00:03:20
course I started a special newsletter in the
00:03:23
VKontakte group, a link to it is in the
00:03:26
description under the video if you subscribe to
00:03:31
this newsletter you will receive
00:03:33
notifications about upcoming lessons as well as
00:03:38
links to previously
00:03:40
published lessons on
00:03:42
some additional materials and there
00:03:44
is also a special chat in Telegram
00:03:49
specifically for this course on the Sharpe axis,
00:03:53
respectively, a link to it
00:03:55
is also in the description, so
00:03:58
there is already free communication in the language with
00:04:02
all participants who are studying the United States
00:04:05
with you are also watching this course, there you
00:04:08
can see links to all
00:04:10
previous entries
00:04:12
and also additional materials and
00:04:14
ask any questions, either I will answer or
00:04:16
someone who already knows in the chat can
00:04:20
also tell you, I also have a
00:04:24
general VKontakte group Telegram price channel blog
00:04:29
where I publish
00:04:30
materials on all
00:04:34
programming languages, as well as entertainment
00:04:36
materials, as well as some general articles,
00:04:39
everything, on these resources you can
00:04:42
read, see everything useful for
00:04:44
programmers,
00:04:45
and also if you
00:04:49
click on the letter in the upper right corner and you can see these are the
00:04:55
notifications for tips, there you can find
00:04:58
links to the playlist and my channel, also
00:05:02
subscribe to the channel and like
00:05:04
if you like this video, and
00:05:07
now I think with the introductory part, we
00:05:09
can safely finish everyone who
00:05:11
wanted to take part in the course, I think they have
00:05:15
already connected so let's
00:05:19
get started and so and so and so and so
00:05:22
our topic for me is most customary
00:05:26
to call them templates, so if
00:05:27
possible I will, if you don’t mind,
00:05:31
use this name,
00:05:34
that is, a template and, accordingly, what is a template, this is a
00:05:37
kind of a
00:05:43
peculiar, well, we can roughly
00:05:46
imagine itself as a variable for the type of
00:05:48
variables, this is such a
00:05:51
tricky definition which,
00:05:53
accordingly, is not entirely correct,
00:05:56
but it describes the basic logic, that
00:06:02
is, we can set
00:06:05
some kind of anonymous
00:06:09
type, whatever we think of calling it, this is
00:06:15
not important, the prince, and in the future we will take
00:06:18
all the places mentioning
00:06:22
this type, we can dynamically substitute the
00:06:26
required real type, that is, we, just
00:06:30
like a variable, we declare a
00:06:32
variable as some kind of box where
00:06:36
we can put any value there, we can
00:06:39
put a screw variable five,
00:06:42
we can put a seven, we can put a ten, it
00:06:44
doesn’t matter, I think I’m
00:06:46
sounding too loud and
00:06:51
so now I made it a little quieter, then a
00:06:54
similar sound is off the charts, I’m
00:06:56
kind of loud today, so
00:07:00
the variable can be represented as
00:07:03
a box where you can put any
00:07:05
values ​​of a certain type and,
00:07:12
accordingly, this is the template,
00:07:16
this is the universal type, this is a generalization, whatever
00:07:19
you want to call it, I see that
00:07:22
they correct me that templates are a slightly different
00:07:24
concept, but there’s a lot of naming on the 1st floor, but I’m used
00:07:29
to it, well, blame me for
00:07:32
this, but in general it’s correctly
00:07:36
called a universal type and
00:07:38
universal types, but we’re not tired of
00:07:41
going templates like this and I call
00:07:45
accordingly, we can define
00:07:49
a template,
00:07:50
that is, a kind of variable, and under
00:07:55
this name some kind of universal we can
00:07:58
substitute
00:07:59
any type of data, that is, not
00:08:01
put a specific value there, but specific
00:08:05
data types, that is, we can declare
00:08:08
tab tab tab tab tab everywhere there and at the stage of
00:08:13
writing the code we like since we will
00:08:15
dynamically substitute int everywhere where
00:08:17
mentioned counts became the value value
00:08:21
in the you passed string our type
00:08:26
became strings everywhere,
00:08:27
this allows us to simultaneously do
00:08:30
essentially dynamic typing, that
00:08:36
is, we do not rigidly define which
00:08:40
specific type
00:08:41
at the stage of writing the code, that is,
00:08:43
a kind we have a speaker,
00:08:45
but at the same time remain strictly
00:08:48
typed, that is, if we set
00:08:50
for this type
00:08:53
that it is this, this will be this everywhere, and the
00:08:56
meaning actually and no other one can be
00:08:58
substituted there, we won’t be able to change it, so
00:09:03
the idea is like this, that is, first a
00:09:08
generalized definition then at the
00:09:11
completed stage at the stage of use in the code
00:09:15
we say that it’s not exactly screws that should
00:09:19
be and
00:09:21
it’s as if we can’t understand anything, we
00:09:23
set a specific int, but now
00:09:27
let’s probably start
00:09:29
practicing, it’s better to show it in
00:09:30
practice I’ll make a smaller camera and run it
00:09:34
like this let me, if you don’t mind, I’ll
00:09:39
change the camera for a
00:09:42
second like this and I’ll be turned in the other direction,
00:09:53
but in short, let’s launch the viral program,
00:09:59
and in the meantime,
00:10:00
throw on some topic, a subject
00:10:03
area that interests you, which
00:10:05
we’ll look at, which
00:10:09
we’ll do
00:10:10
classes on today any topic that may
00:10:15
be your subject area in which
00:10:18
you are doing an assignment or just throw in some
00:10:21
interesting topic or whatever,
00:10:24
that is, write directly in the comments and I will
00:10:27
then see what will be the most interesting
00:10:32
and then, accordingly, I will either
00:10:35
choose the first one or the one that suits me better
00:10:36
I’ll like it after all, I’ll be able to
00:10:39
influence it, so let’s create a console
00:10:43
application in the same way, let’s
00:10:45
call it
00:10:48
12 free word 447, let’s leave it where the guy with
00:11:10
the shops at home, we can if there is
00:11:15
a desire,
00:11:16
if no one else has any ideas, in
00:11:18
principle, I can take the same topic without any problems
00:11:20
which we took last time
00:11:24
or or something of our own, come up with something if
00:11:29
now in the near future no no you won’t
00:11:32
write anything, then we’ll
00:11:36
stir up something, well, it looks like there’s
00:11:40
nothing like that, let’s see then
00:11:45
that we had a sporting goods store,
00:11:51
yes, let’s do the same topic and let's leave it so
00:11:58
that we need we need to create a class
00:12:04
let it be
00:12:06
sequential, well, let's say
00:12:13
sporting goods gasin,
00:12:15
we had a product there in my opinion,
00:12:22
let's talk about the apple calorie counting, yes
00:12:29
we had calorie counting, everything I remembered
00:12:31
memory memory is not the same memory is already this this is
00:12:38
exactly the topic of my today’s
00:12:40
VKontakte newsletter, so product, so we create a class
00:12:47
product public product, so we
00:12:59
had a product, no, we won’t look in that
00:13:03
direction today, that is, we’ll
00:13:06
just look at some kind of universal product, and
00:13:09
for it we’ll define it like this:
00:13:12
we have a public string, by the way, you
00:13:17
know how you can quickly write
00:13:20
properties, that is, you can try to write a
00:13:24
sermon and
00:13:25
tab twice and we can create this
00:13:28
so-called snippet, it turns out to be full, that’s what
00:13:31
they are called, which just
00:13:35
allows you to set just such quick
00:13:37
string properties name about everything we created the
00:13:46
properties of
00:13:47
rob and
00:14:00
accordingly created a product for the
00:14:02
product we defined
00:14:04
the name and determined its quantity and
00:14:09
look now if we want to create
00:14:12
some new product to take into account our
00:14:20
calories,
00:14:21
let’s also add a third parameter here,
00:14:27
samples are important int and what we already have energy there, that
00:14:36
is, the number of calories, let’s
00:14:42
write down the constructor public product name
00:14:58
in here we will mark that there should be a
00:15:13
check, but we won’t write it now
00:15:15
so we can waste time checking how we
00:15:20
do it correctly, I will believe
00:15:28
by the way, a very useful thing, this is
00:15:32
it darling,
00:15:33
when you write in this format,
00:15:35
you can sort of
00:15:40
open the list of tasks and you will find all
00:15:44
your that arches, that is, comments in
00:15:46
this format, that is, listen to yourself,
00:15:50
a colon there after this comment, we
00:15:53
will display a special panel, the
00:15:55
so-called a list of tasks and at any
00:15:59
time you can go to this place from
00:16:03
any section of the code and fix something there, it’s a
00:16:05
very convenient thing, I highly
00:16:07
recommend using it,
00:16:11
check the input and install the documents after
00:16:13
that, everything is fine now we
00:16:38
can create our product product
00:16:41
let’s three yours new product
00:16:51
apple so we still had a volume of
00:16:58
100 grams no string type and energy
00:17:05
let it be 100 calories great great
00:17:11
very convenient very cool but look
00:17:17
suddenly it happens suddenly suddenly
00:17:20
such a need happens customers come to you and
00:17:23
say Vasya
00:17:28
everything is gone our application is working
00:17:32
wrong and we are only setting an
00:17:38
integer value, but we still need fractional
00:17:41
values, so you go and start
00:17:45
editing the class accordingly, you change
00:17:48
the type here to double double double there, they changed
00:18:04
everything more or less perfectly, that is, the
00:18:08
customer came, something bitter
00:18:10
says that it is already possible how to set strings with
00:18:14
fractional values, everything is fine, then
00:18:17
after two weeks the customer comes to you and
00:18:19
says Vasya, everything is gone, everything is bad. We are
00:18:23
not happy with the fact that the
00:18:28
floating point values ​​are
00:18:30
rounded incorrectly here and there, there is a failure,
00:18:33
defects, everything is bad, make it for us
00:18:37
so that there is an exact number of characters
00:18:41
after comma, you go to your class and
00:18:45
start sawing everything, hope it’s small,
00:18:50
it’s fine, you change it,
00:18:51
you change it, but imagine
00:18:55
that this is not such a trivial application
00:18:57
and there, let’s say, one hundred and five hundred
00:19:00
lines of code are scattered throughout, that is,
00:19:05
that’s the problem, okay, we spent time,
00:19:08
changed everything fine, and then to you
00:19:11
the customer comes and says Vasya, forgive
00:19:16
us sinners, but we need to make sure
00:19:19
that in the user settings the
00:19:22
users themselves can set because
00:19:26
they need to count calories with fractions
00:19:29
with only a fixed number of
00:19:31
characters, , or without commas at all,
00:19:35
and here you are faced with such a
00:19:37
problem that you you will need to create
00:19:39
three
00:19:40
absolutely identical classes with different
00:19:43
data types that will completely
00:19:46
duplicate each other, but no matter how
00:19:58
simple it is because you take it there and
00:20:01
you are faced with, say,
00:20:04
memory overuse because for children a 128-bit bit and the
00:20:09
type, accordingly, it will
00:20:11
suddenly take up more memory there is some kind of
00:20:13
highly-highly loaded system where
00:20:16
you have to take care of it, plus
00:20:19
some additional plus, this
00:20:21
case is that the user himself must
00:20:24
set something, well, again, this is
00:20:27
such a slightly exaggerated example, of course the
00:20:29
use of templates is
00:20:33
only necessary where it really is
00:20:35
necessary, but now I’m just trying to
00:20:37
demonstrate
00:20:38
the case when
00:20:44
used templates can be used, so
00:20:51
creating three identical classes for
00:20:54
everything with absolutely the same logic is
00:20:58
contrary to one of the
00:21:06
programming paradigms, object-oriented,
00:21:08
but in general there is an addition to such
00:21:12
programming paradigms, the so-called driver
00:21:15
tons of intrepid and sat down, don’t repeat it, that
00:21:19
is, writing the same code three times is
00:21:21
not optimal, it’s dangerous because
00:21:24
in case of any updates,
00:21:26
changes will need to be made
00:21:29
in three places, somewhere you can make a mistake,
00:21:32
somewhere you can miss something making
00:21:34
bugs and a baguette is bad, so in the C language
00:21:40
sharp there are these
00:21:42
universal types, that is, we
00:21:45
can design a class in such a
00:21:47
way that we can, if necessary,
00:21:52
specify the type in the future,
00:21:58
accordingly, what we
00:22:00
need for this, for this we,
00:22:05
accordingly,
00:22:07
when declaring a class, specify that’s exactly the
00:22:13
name of our anonymous type, the
00:22:19
letter t is most often used, but that’s how it is
00:22:21
accepted, it comes from the word template
00:22:26
template, that is why they call them templates,
00:22:28
that is, products, and now we can
00:22:33
specify our anonymous type right inside the class here This is
00:22:38
exactly how we
00:22:43
define ttt everywhere and note
00:22:50
that our typing remains
00:22:54
strict, that is, we have indicated that it is time that the
00:22:59
argument to the function is passed type t and
00:23:02
the property of type t and they cannot
00:23:04
differ, that is, we set
00:23:07
this type for the class once for a specific
00:23:12
instance of a class and we can accordingly
00:23:15
be sure that within one
00:23:17
instance of the class this anonymous type
00:23:20
will be replaced everywhere by the same one,
00:23:25
now how to use it now, I
00:23:30
beg your pardon with the mouse, now,
00:23:34
accordingly, when
00:23:35
in the constructor we just
00:23:38
indicate in angular in brackets is the
00:23:40
specific type that we need, that is,
00:23:43
if we specify the int type here, we
00:23:46
immediately get a substitution,
00:23:49
you see, that is, if we initially
00:23:52
hover over the class, our
00:23:58
intellisense assistant shows us that it is not
00:24:01
we have this universal type and
00:24:04
while it is not specified
00:24:06
and this ti will be substituted for the second and
00:24:09
for the second and third
00:24:11
constructor arguments in angle brackets,
00:24:13
we indicate a specific type
00:24:15
and we immediately have the transformation of
00:24:18
our
00:24:19
universal constructor with a
00:24:21
universal type into a constructor everywhere
00:24:26
with type int, that is, we immediately have a system
00:24:29
swears that the type of decim
00:24:32
cannot be perceived as int for us, so we
00:24:37
can already set it like this, and
00:24:40
next to it there are 2 exactly the same argument
00:24:43
an instance of the class new product to go small
00:25:00
banana we will already require
00:25:05
accordingly, too, that it be that
00:25:18
we were just after all, the value is with a
00:25:22
fixed point, that is, you see
00:25:24
bowl, it has already been extracted, it no longer accepts it, we
00:25:30
must pass the argument on the side
00:25:33
and, accordingly,
00:25:35
now to how, in essence, quotas when
00:25:38
here we passed some
00:25:41
value of type into the argument, essentially everywhere inside and
00:25:50
inside our class, our t will be replaced
00:25:54
by
00:25:57
childhood, in fact, how to imagine this is the
00:26:01
easiest way: someone just took it
00:26:04
and with a simple replacement
00:26:10
t-so they just took the current document and
00:26:14
replaced it like that, but of course it
00:26:19
replaced it incorrectly because all the letters
00:26:22
t replaced the entire word here like this, like
00:26:31
this, they just took it and replaced it and
00:26:35
that’s it, that’s exactly how our
00:26:42
templates work, our
00:26:45
these universal types, our generalizations,
00:26:50
whatever they are called
00:26:53
accordingly, and we can also for the
00:26:58
first thing that comes you probably already
00:27:01
remember this form of notation with
00:27:04
angle brackets you We’ve already
00:27:05
encountered it, that is, where we
00:27:08
used it, if you remember, don’t you remember that
00:27:12
we have sands, just the same, she has a sheet,
00:27:23
just the same, when creating lists, we
00:27:27
use our our
00:27:35
communication, these are our templates,
00:27:37
look at what the list class looks like from the inside
00:27:41
or sheet,
00:27:44
if anything, this can be done very simply,
00:27:47
if you didn’t know, hover your mouse over the
00:27:51
class that interests you and
00:27:55
press the F12 key and you immediately
00:27:58
go to the implementation of this class
00:28:03
to see the specific one, that is, we
00:28:05
cannot, this is the standard implementation that is
00:28:11
part of the dot net framework
00:28:14
but we can look at the interfaces and as
00:28:17
you can see here we have exactly the same
00:28:20
generalization template and
00:28:23
looks something like this, that
00:28:27
is, a sheet t something like this and so on and on
00:28:34
what else I want to say is whether there will be a
00:28:39
practical lesson on creating a project based on the
00:28:41
material covered Yes, of course,
00:28:44
and I’m even planning more than one thing after
00:28:47
we look at the syntax of the language,
00:28:52
the syntax of the language in its entirety, then we’ll
00:28:55
look at structures and algorithms and
00:28:59
Potter, that is, in fact, this is some
00:29:02
kind of practice, but let’s just say it’s still a
00:29:06
little bit of vacuum practice, and after
00:29:09
we We will already study specifically all
00:29:11
the syntax and all the basic structures and
00:29:14
algorithms and pattern, and after that I
00:29:16
plan to directly take the project and from scratch on
00:29:21
streams there over the course of several lessons,
00:29:24
the brothers will develop with all the explanations with
00:29:28
comments, you will also probably
00:29:32
help take part in something to
00:29:34
suggest what
00:29:38
to throw in some funny topics,
00:29:41
so by the way, I talked about this a little
00:29:46
earlier, apparently you didn’t
00:29:49
connect first before practice will be practice
00:29:52
and just for sysharpa
00:29:55
for lessons and just for sysharpa and,
00:30:00
accordingly, for individual areas of it
00:30:04
like unity, I plan
00:30:06
consider wpf winforms
00:30:12
wcf and maybe to Samarin, maybe, but
00:30:18
I’m not sure about that yet, yes I recently
00:30:23
connected, so it’s like a little bit of
00:30:28
paragon we talked about the future, now
00:30:31
we return to the present, we can
00:30:36
pass any type, any type
00:30:43
anonymous, but allowed or how many we
00:30:47
you will need to
00:30:48
call it by the way, not necessarily with one
00:30:50
letter, you can quite calmly
00:30:53
use more informative
00:30:58
names, but more often than not, if we
00:31:01
use one, then we can just
00:31:05
specify it with the letter t, this is customary
00:31:09
because it is a template
00:31:12
here and here, respectively, if we
00:31:15
use 2
00:31:18
universal ones type, we must also
00:31:21
pass 22 real types in the constructor
00:31:27
no, this is a template,
00:31:29
this is the trick, respectively, get
00:31:34
int int or
00:31:37
in dc mall that is, if we set it as you see, the
00:31:43
first type for volume
00:31:46
will be just kent ova and for energy it
00:31:50
will be the decimal type again, everything is as we
00:31:54
will set it ourselves for our class, but
00:32:02
if we don’t set it,
00:32:05
it will swear at us where
00:32:09
such a double argument is actually used, this is
00:32:12
also a
00:32:14
new
00:32:16
dictionary dictionary, that is, as you can see, there are
00:32:20
already
00:32:24
more detailed names here, but as you can see, too
00:32:27
starts with the letter d type of key type of
00:32:30
key template includes template key or
00:32:35
t pour out the value who doesn’t know dictionaries
00:32:38
this is a simple key-value pair
00:32:40
key-value key-value
00:32:46
if they are all different inside the class itself
00:32:50
so no one forbids you to use a
00:32:54
specific type and you want if you
00:32:59
want to create a lot of things here like this,
00:33:02
pass one hundred and five hundred types like this,
00:33:05
this is bad, this is a design error,
00:33:08
it means your class is designed too
00:33:10
cumbersome, too wrong, this
00:33:15
should not happen, that is, 102 maximum damn
00:33:19
three types, I have
00:33:22
almost never seen three, that is, here is one two
00:33:25
types is the
00:33:27
top thing you can ask, but if they are
00:33:33
all different inside your class, then damn,
00:33:37
this is a little wrong, that is, you
00:33:40
must select some types that in
00:33:43
reality will constantly change for you,
00:33:46
but if you have, let’s say for the name,
00:33:50
you see for the name is always a thong,
00:33:53
but the text value is always the same and
00:33:57
remains the text for you, it doesn’t change, we
00:33:59
can change the amount of energy, but
00:34:05
we don’t need more, there may be another
00:34:09
hundred and five hundred other parameters,
00:34:12
but they must be either
00:34:19
specific or accordingly
00:34:21
to use these types, respectively,
00:34:25
you just need to look at the architecture
00:34:27
so that
00:34:31
they are written somehow better,
00:34:33
so our dictionary and nsstring and,
00:34:42
accordingly, our map takes a
00:34:46
kite, respectively, two arguments
00:34:49
value five line
00:34:53
5 in approximately this way, and
00:35:00
if nightmare thank you thank you for
00:35:07
the support very nice really super
00:35:10
thank you very much nightmare that's
00:35:19
accordingly as you can see if we
00:35:22
change the string type here then we again have the
00:35:28
quantity
00:35:29
Vasya you're wrong here there should be a string
00:35:33
and that's it and you need to change the settings then
00:35:36
everything will work
00:35:37
feature by the way mapo but its structure is
00:35:41
generally called called mapo
00:35:43
dad who is a dictionary in a scarf, it is customary to
00:35:49
call it a dictionary, respectively,
00:35:52
the key, this first value
00:35:54
can be unique, that
00:35:58
is, you cannot add an element with the same value a second time,
00:36:00
you will get an
00:36:04
error at the execution stage that is,
00:36:09
this is such an introductory
00:36:13
acquaintance with data structures about it,
00:36:18
we get that an element with such a key
00:36:20
already exists using words and we
00:36:23
guarantee uniqueness by key and
00:36:27
also quickly, quickly, and quickly obtain the
00:36:32
value of this, a
00:36:35
good structure often has to be
00:36:37
used, take note, it will come in
00:36:39
handy
00:36:41
so let's return to our template to
00:36:44
our template to our universal
00:36:46
type what else I want to say is let's
00:36:49
return a single type as follows and
00:37:04
now look we can set
00:37:08
certain restrictions on our template,
00:37:13
what does this mean, that is, we can
00:37:16
let's say we have just the same product
00:37:21
and Let's say we'll make the apple class, add the
00:37:27
apple class, which we will have
00:37:35
inherited from the product, as you can see, we
00:37:45
can let's do it with the product then, let's do it like this, so
00:38:03
he doesn't like it, and the
00:38:35
access modifier is
00:38:36
seriously missing an argument
00:38:50
corresponding to the
00:38:55
product string and Valin I am a constructor
00:38:59
forgot to define your division public
00:39:36
construct the bass
00:39:45
name now everything is fine and
00:39:56
now now note that we
00:40:11
can do even this often I change
00:40:25
temporarily for this particular example
00:40:33
so look we have the apple type
00:40:50
which is inherited from the product
00:41:00
let's say here so on and so on, well, for
00:41:10
example, let's create another class class by
00:41:19
but ours which will also be
00:41:27
inherited from the product
00:41:36
now it was created correctly correctly
00:41:40
and now now finally we are
00:41:44
creating our last class
00:41:48
let it be let it be a
00:41:54
meal that is and getting a meal,
00:42:09
look what the main point is, to
00:42:15
create a meal we must indicate
00:42:21
exactly our type our type
00:42:27
but but but
00:42:30
we also mean that eating
00:42:32
is possible only with a product only with a product
00:42:36
but we can quite easily create it like this in our case
00:42:43
war i think is
00:42:50
equal to
00:42:51
and think mind that’s accordingly and how
00:43:02
exactly we will implement it here,
00:43:07
let there be a public
00:43:15
howl, etc.
00:43:32
here we define some
00:43:37
properties
00:43:40
public
00:43:50
[music] the
00:43:51
total volume of food intake
00:43:57
will show and here we accordingly what
00:44:02
we will make the product and with ours
00:44:20
this type we just want to
00:44:24
get our properties
00:44:27
our properties but as you can see we can’t
00:44:30
first of all we don’t we can get a
00:44:35
specific property, that is, we want to add a product to the
00:44:39
general will of our property
00:44:44
.
00:44:49
let’s take it multiplied by the energy product,
00:45:05
but we can’t do it
00:45:08
because it’s like
00:45:09
we have an expansion method
00:45:13
and with us he can’t understand
00:45:17
what it is, how to work with it, he doesn’t
00:45:22
know anything about it and besides, what’s the
00:45:25
main thing The problem is that instead of a
00:45:27
product, we can pass a
00:45:29
new type int o exit and
00:45:32
the system won’t tell us anything bad about it,
00:45:34
since our type here
00:45:39
is universal, respectively, and
00:45:42
we can substitute any universal type here,
00:45:46
but in order to avoid this
00:45:50
situations of such a design error
00:45:52
when we may be faced
00:45:55
with the fact that we will not behave
00:46:03
as expected and there is a
00:46:07
limitation, that is, we can set
00:46:09
specific restrictions on the type t,
00:46:11
here we can set that so there we
00:46:17
have gdp colon
00:46:29
and after that we indicate the base type
00:46:33
product, and here we already
00:46:40
get this feature that our type t
00:46:44
can now only be a product or
00:46:51
any of its successors, that is, the feature
00:46:55
is not only a product,
00:46:57
but in the same way we can here it
00:47:01
pass our apple and it will be
00:47:07
correct because these clouds
00:47:08
are not the heir of the product, but at the
00:47:12
same time our line will not be the heir of the product,
00:47:16
so it
00:47:19
will not be accepted, which is logical,
00:47:22
we get a certain security, we
00:47:25
get access to all the properties a
00:47:30
couple of miles with parameters and that is, and in the same way,
00:47:35
in fact, we can
00:47:37
set anonymous, these are non-
00:47:43
anonymous generalized for types
00:47:47
and for a product, if we set here, then
00:47:52
we can here, roughly speaking, let’s have
00:48:05
a little time, that is, for
00:48:16
eating, we will set in first, that the type of
00:48:22
product is your product, that is, this
00:48:29
type will be inserted into the product and now we
00:48:36
can set the product
00:48:44
young,
00:49:03
roughly, here’s
00:49:04
the idea, okay, let’s not go too deep into
00:49:08
this right now, we’ve
00:49:09
already figured out the types in the types, the
00:49:14
main point is that it’s important for you to understand that
00:49:19
that we can set restrictions on
00:49:23
types, what we can set restrictions
00:49:26
on types,
00:49:29
restrictions on types, we have exactly
00:49:32
the following: we can set a specific
00:49:36
class,
00:49:40
then we will have
00:49:46
either you or it as a type, or
00:49:51
this particular class or all its
00:49:54
descendants here maybe
00:49:56
an interface if we have an implemented
00:50:00
interface there is some kind of
00:50:01
product or in and the number of the able, that’s just
00:50:09
what we’ve got here, it could
00:50:15
be an interface and all the classes that implement
00:50:18
this interface,
00:50:20
then there could be a keyword
00:50:27
labor
00:50:29
structure, that is, type maybe only
00:50:34
the structure that we have such a structure is a
00:50:36
kind of similarity to a class but slightly
00:50:39
different in that it is stored on the
00:50:41
stack and the fact that it is a little smaller
00:50:48
does not provide all the capabilities of classes,
00:50:51
but at the same time it
00:50:52
has its advantages, for example the
00:50:55
same do the time we have is a
00:50:59
structure here we can have a
00:51:02
keyword class the keyword
00:51:06
class we have says that the type
00:51:09
must necessarily be a class that is,
00:51:11
this is not a structure we have a distinction
00:51:13
with the help of these keywords either a
00:51:16
class or a structure we define either
00:51:20
this or that and more one limitation
00:51:24
that we may have looks like this,
00:51:28
new and parentheses, this means that the
00:51:32
class must have a public
00:51:36
constructor without parameters, that is,
00:51:41
in this case, our product will not
00:51:48
really work, why, well, let’s say
00:51:55
these clouds if we want to go here pass
00:51:59
apple
00:52:01
it will not suit us because apple
00:52:07
does not have constructors without parameters, if we
00:52:10
add a public constructor without
00:52:13
parameters, this is the one we
00:52:20
like, available, but at the same time, a banana that
00:52:27
does not have such a constructor
00:52:29
remains inaccessible, these are the
00:52:32
restrictions, respectively, the restriction
00:52:35
is set using the keyword in and
00:52:39
accordingly, indicating either a
00:52:41
specific class, but most often they
00:52:44
still use the class,
00:52:46
that is, we will most likely have it like
00:52:52
this, so what remains for me to say on this
00:52:58
topic is that if we have several
00:53:00
parameters,
00:53:01
we can have several pvt nevian
00:53:11
let it be what we have some ainu of the
00:53:27
apple world
00:53:28
and let it be like this, that is, for the first
00:53:31
type we set restrictions that there should
00:53:34
be a product or successor for the second
00:53:37
type and the number was or a class and
00:53:41
implementing this interface,
00:53:44
respectively, here we can already
00:53:48
pass let’s say a sheet and just like that
00:53:58
we have a sheet that implements interface a and number was
00:54:02
so we can transfer it here, but at the
00:54:04
same time we can’t transfer the same product here,
00:54:09
no luck it doesn’t work out
00:54:16
this way and now probably the last thing
00:54:19
I want to
00:54:21
say is the default keyword, that
00:54:25
is, look at us often We are faced
00:54:28
with such a need as setting a
00:54:31
default value, that is, if our
00:54:37
product is typed,
00:54:44
let’s say this and let’s say we want to
00:54:54
install it differently, let’s say energy,
00:54:57
which we have as ted, we also
00:55:00
want to set it as a default value,
00:55:03
but we don’t know what exactly
00:55:06
it is install that is, we can
00:55:07
try at our own peril and risk
00:55:10
install on but here this is exactly how we
00:55:13
are faced with the fact that this cannot be done,
00:55:16
that is, in int we cannot assign cash to
00:55:21
int and with our own channel it was not a zero
00:55:24
type, so we do not We can perform this
00:55:27
operation like this, but how do we find out
00:55:30
what specific type the template will have? And
00:55:33
for now, the development environment itself will tell us
00:55:35
that we should use the
00:55:40
faut keyword and the default value for this will be set here,
00:55:44
let’s say it
00:55:48
will be 0 for the line and, in my opinion, an empty
00:55:52
line for the class it will be on but in
00:55:56
this way, so this is
00:56:00
exactly how
00:56:04
this default value will work for us. I’ll immediately
00:56:08
check if I’ve told you everything. If you
00:56:13
have any questions, you can
00:56:15
write them now, I’ll try to answer you, and
00:56:19
after that I’ll I’ll just
00:56:20
write homework and by the way, what
00:56:33
else I forgot to mention is that we have a
00:56:39
generic type that can be returned, that
00:56:42
is, we can quite easily
00:56:48
use our anonymous type return
00:56:56
default as the return argument of the method, and in this case
00:57:01
we have just anyway, everything will
00:57:05
work just fine, that is, if in this case we
00:57:10
specify a specific theta type,
00:57:13
we will have it returned specifically
00:57:15
and this is the value of this specific type
00:57:19
that we will create at the call stage,
00:57:23
let’s say so, we will need to correct it a little
00:57:29
before posting on
00:57:31
git hop so that there is not some kind of
00:57:33
game here at all, so today I will most likely
00:57:36
post it and then, if necessary,
00:57:42
look at the
00:57:44
homework homework
00:57:55
so what we do is necessary in your 3d there is no
00:58:03
moment of power and divide not up the
00:58:14
base class and several years before you
00:58:39
add to
00:58:42
[music]
00:58:46
let's add only the base
00:58:52
class, well, let's correct the universal
00:59:01
type create a class that will create a
00:59:26
class that will accept
00:59:31
as a non-
00:59:37
social type as a universal
00:59:42
type base class
00:59:45
but that's exactly what we did today
00:59:51
and accordingly take a break from what
01:00:15
I want from you, I want you to
01:00:18
take the paint and try to implement with your own hands
01:00:22
approximately what I showed you today
01:00:26
in class, that is, you must define a
01:00:30
class that is
01:00:31
truly a universal product, then we
01:00:43
must have some kind of class that will be
01:00:46
it to use and what kind of
01:00:51
it will be accepted to be
01:00:54
saved as a limitation and
01:00:56
then accordingly it will need to be
01:01:01
used
01:01:25
Thank you all very much for coming to the
01:01:30
class please put a like under
01:01:33
the video because it is really
01:01:35
useful for promotion to attract
01:01:39
new people also do not forget that there are
01:01:45
links to the VKontakte group and to
01:01:48
my other resources there telegram prices website
01:01:51
I actually have a lot of things so
01:01:55
subscribe and don’t miss classes,
01:01:59
study and try everything, be sure to try everything
01:02:02
in practice, this is very important,
01:02:05
that is, what I told you is
01:02:07
only the very beginning of the
01:02:10
learning process, so you definitely need to
01:02:14
try everything with your own hands, be sure to
01:02:16
write, that’s the only way you
01:02:19
’ll learn something good I'm looking forward to everyone at the next
01:02:22
lesson this Thursday,
01:02:25
I will be very glad if you join
01:02:29
everyone, thank you very much and bye everyone

Description:

Обобщения или шаблоны (Generic) в языке программирования C# На этом занятии мы рассмотрим Универсальные шаблоны в языке программирования C#. Также часто встречаются названия обобщения, дженерики или generics. Они позволяют определять так называемые универсальные типы данных, которые позволяют динамически определять тип, при этом оставаясь языком со строгой типизацией. ----------- ПОДПИШИСЬ на соцсети: 🔴 TELEGRAM: https://ttttt.me/joinchat/AAAAAEOzZfpJvCkPaOyurA 🔴 VK: https://bit.ly/vk_codeblog 🔴 INSTAGRAM: https://www.facebook.com/unsupportedbrowser 🔴 Яндекс Дзен: https://dzen.ru/codeblog 🔴 FACEBOOK: https://www.facebook.com/unsupportedbrowser 🔴 TWITTER: http://bit.ly/twit_codeblog 🔴 Мой блог: https://bit.ly/site_codeblog ----------- ПОДДЕРЖИ развитие CODE BLOG: 💲 Донат: https://www.donationalerts.com/r/shwanoff 💲 Спонсорство: https://www.patreon.com/codeblog ----------- СМОТРИ мои обучающие курсы: 👉 УЧИМ ШАРП: https://www.youtube.com/watch?v=p9QxqrwkPbA&list=PLIIXgDT0bKw4OmiZ9yGmShKsY0XncViZ8 👉 ПРАКТИЧЕСКИЙ ИНТЕНСИВ #1: https://www.youtube.com/watch?v=eQph6ZT4X5w&list=PLIIXgDT0bKw7AOFNyc2_FGYDj_52AclvV 👉 ПРАКТИЧЕСКИЙ ИНТЕНСИВ #2: https://www.youtube.com/watch?v=XHuUN1u8ZPE&list=PLIIXgDT0bKw4M1_5JX0LRHdjQXSR0Upfw 👉 СТРУКТУРЫ ДАННЫХ: https://www.youtube.com/watch?v=hZYQmNJBsKM&list=PLIIXgDT0bKw4DB9toGU73ntyYIZV7aJi5 👉 АЛГОРИТМЫ СОРТИРОВКИ: https://www.youtube.com/watch?v=PD1Nn4fHcts&list=PLIIXgDT0bKw4n6pwBjymd3wCPyQ3_SLMo 👉 ОТВЕТЫ НА ВОПРОСЫ: https://www.youtube.com/watch?v=Xb1prk0to9I&list=PLIIXgDT0bKw7oKRr2c1n-e_dUgR8Aqdsi 👉 IT ПЕРЕОЗВУЧКА: https://www.youtube.com/watch?v=Q1VAd1xUtxI&list=PLIIXgDT0bKw5O-kShBcWT0bk7Ev8lZYmV 👉 НЕЙРОННАЯ СЕТЬ: https://www.youtube.com/watch?v=woohvQE73AI&list=PLIIXgDT0bKw7VnfMl5wWW_kjmmCrHjfvb 👉 ПАТТЕРНЫ ПРОЕКТИРОВАНИЯ: https://www.youtube.com/watch?v=RsU2K5Cuu_U&list=PLIIXgDT0bKw5gOlwxV1TigVAeOPhR6kes 👉 CODE REVIEW: https://www.youtube.com/watch?v=hhYZEts63rQ&list=PLIIXgDT0bKw6FSCulrNWzWMRf0cH0fz0_ 👉 CLR via C#: https://www.youtube.com/watch?v=m_nvUAXdbOY&list=PLIIXgDT0bKw6i4jQkHVgIrnsP-DcvBieq ----------- Кстати, меня зовут Шванов Вадим, и я профессиональный .NET разработчик с 2011 года и автор этого канала CODE BLOG. Я рассказываю про IT технологии и веду абсолютно бесплатный курс по языку C# с нуля. В его рамках мы рассмотрим как базовый синтаксис языка C Sharp, так и его практическое применение и специальные технологии, такие как ASP .NET, .NET Core, ASP.NET MVC, Unity, WPF, структуры данных и алгоритмы, с#, dotnet, паттерны проектирования, информатика, csharp, программное обеспечение и многое другое. Для меня важно не только показать практическое применение языка си шарп, но и объяснить основную идею и базовые понятия Computer Science. В качестве основного инструмента разработки используется Visual Studio c# и проекты на Visual c#. Если вам нравятся такие каналы как хауди хо, айти борода, Soer или ExtremeCode, то здесь вам точно понравится. -----------

Preparing download options

popular icon
Popular
hd icon
HD video
audio icon
Only sound
total icon
All
* — If the video is playing in a new tab, go to it, then right-click on the video and select "Save video as..."
** — Link intended for online playback in specialized players

Questions about downloading video

mobile menu iconHow can I download "Обобщения или шаблоны (Generic) в C# - Учим Шарп #12" video?mobile menu icon

  • http://unidownloader.com/ website is the best way to download a video or a separate audio track if you want to do without installing programs and extensions.

  • The UDL Helper extension is a convenient button that is seamlessly integrated into YouTube, Instagram and OK.ru sites for fast content download.

  • UDL Client program (for Windows) is the most powerful solution that supports more than 900 websites, social networks and video hosting sites, as well as any video quality that is available in the source.

  • UDL Lite is a really convenient way to access a website from your mobile device. With its help, you can easily download videos directly to your smartphone.

mobile menu iconWhich format of "Обобщения или шаблоны (Generic) в C# - Учим Шарп #12" video should I choose?mobile menu icon

  • The best quality formats are FullHD (1080p), 2K (1440p), 4K (2160p) and 8K (4320p). The higher the resolution of your screen, the higher the video quality should be. However, there are other factors to consider: download speed, amount of free space, and device performance during playback.

mobile menu iconWhy does my computer freeze when loading a "Обобщения или шаблоны (Generic) в C# - Учим Шарп #12" video?mobile menu icon

  • The browser/computer should not freeze completely! If this happens, please report it with a link to the video. Sometimes videos cannot be downloaded directly in a suitable format, so we have added the ability to convert the file to the desired format. In some cases, this process may actively use computer resources.

mobile menu iconHow can I download "Обобщения или шаблоны (Generic) в C# - Учим Шарп #12" video to my phone?mobile menu icon

  • You can download a video to your smartphone using the website or the PWA application UDL Lite. It is also possible to send a download link via QR code using the UDL Helper extension.

mobile menu iconHow can I download an audio track (music) to MP3 "Обобщения или шаблоны (Generic) в C# - Учим Шарп #12"?mobile menu icon

  • The most convenient way is to use the UDL Client program, which supports converting video to MP3 format. In some cases, MP3 can also be downloaded through the UDL Helper extension.

mobile menu iconHow can I save a frame from a video "Обобщения или шаблоны (Generic) в C# - Учим Шарп #12"?mobile menu icon

  • This feature is available in the UDL Helper extension. Make sure that "Show the video snapshot button" is checked in the settings. A camera icon should appear in the lower right corner of the player to the left of the "Settings" icon. When you click on it, the current frame from the video will be saved to your computer in JPEG format.

mobile menu iconWhat's the price of all this stuff?mobile menu icon

  • It costs nothing. Our services are absolutely free for all users. There are no PRO subscriptions, no restrictions on the number or maximum length of downloaded videos.