Presenter:Mike Taulty
A quick look at the new Object Initialiser feature in the C# language version 3.0, which lets you create and initialise an instance of a class all in one line of code regardless of constructors.
The following text is a software generated transcript of the video. Click on a minute link to jump to a location within the video
Minute 0
Well and does not have a good session is one of a series of short and it was where we spent our examiners just looking out and do things as visual studio net framework minus like Tolkien and working the developer and platform group in Microsoft in the UK and this is one of a series of videos about changes prospective changes coming in the third version of the sea shark language normally go under the banner of language integrated query or the link bar in the shortage of his report are the features and others look at what they do for us and you have the facilities at on five I saw them a preview of link from the MSDN website and look at object initialises and really simple things and added and the language so it is and the family project in here and will use them in a previous builder console application in the foot that in mind that you can video folder and will call it project one that s fine but at
Minute 1
At any bits that we don t need in the first instance have look at the code here and just am a winner would have with any of that or even that such as get this down to the very fair minimum and were ready to start I ve is in code so this is a really simple thing to understand imagine that you ve got some kind of classless over classical person or property on record on first name that will property on local last name property on their called age you got it last person are not done anything around the constructors of this that make the default constructor explicit so we can constructor we got first and last name and age if you want to create one of these things given this single constructor than what you have to do is initial as a person p
Minute 2
Person and if he wanted to set the name on the age and the sorry first and last name in the age of 50 office manacles friend and so on and so forth he s got an old chap Fred and that s really that ladies are class allegedly given a construct an explicitly took an first name last name and age and may be any combination of the sensitivities of writing quite a few constructors here to initialise various of his properties depending on what s only wanted to initialise construction time or nothing about his object initialises of version 3 of the language brings in its out with a single line of code as a present for lines of code or we can do it we can so want a new person and we can enter a first name because Fred Stoodley Fred last name if
Minute 3
Age equals 22 little at all properties here a bill that ignored it and have a sense of three version 3 in telephone stuff installed here them compilation from the and frankly it does exactly what you would expect it to do this is not some kind of clever runs and trick is just the compiler feature so if it is a go and look at the buying has been produced here and use it to light reflector system binaries called project one exe year we can go and have a look at that root out army method she s in there and using a code has been written in a greater person for the first time property Larsson profited the age property it looks like the compiler is doing something with two person references here you ve got to assume that perhaps it does offer more complicated scenarios and always gone screen
Minute 4
Essentially all doing is creating on others instances setting its vast encircling its age using a different syntax from what we had before but were achieving exactly the same thing now is understood over exciting it turns out that combines were the other main features this becomes quite a powerful thing to be able to do s fair in the sea shops in sight of version 3 and stands today just to be aware that that s a change from the version to syntax A very short of their and a very short summary and object initialise can set a number of properties on an object as we instantiated it looks like construction you write a single line of code that seems to be initialising yoghurt then we saw that the compiler is distilling a little transformation for is an explicitly going on the properties for us like we saw Middleton reflector when you have more information at each other s and three and language integrated
Minute 5
And well as a site of MSDN link is there on the screen also if you follow that link is provided to that page privacy sharp version 3 language specification as it stands that they would give you all the information you need on what that means is version 3 a and something in the specific little video fundamentally unjust mike o Microsoft com or nothing to offer the thing and will catch you next time you become one of his
Click here to go to original video page
Wednesday, July 23, 2008
Video: C# Version 3.0 - Object Initialisers
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment