I'm beginner when it comes to OOP. Yesterday I was trying to read some mvvm/wpf examples and of course I get into trouble... I have some problem with understand some of code below:
{
class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Addres { get; set; }
}
This is just normal Person class, nothing really unusal here. The problem is that I can't understand below code:
private void SayHi_Click(object sender, RoutedEventArgs e)
{
Person person = new Person
{
FirstName=FirstName.Text,
LastName=LastName.Text,
Addres=Address.Text
};
The part that I do not understand is:
Person person = new Person
{
FirstName=FirstName.Text,
LastName=LastName.Text,
Addres=Address.Text
};
I'm not sure what this is exactly. I thought that every new object should be initialized like this one: Class class = new Class();. Why there is no () after "new Person"? Instead of () we have {}. I know that we can use default, parameterized, static and private construcotrs. Could someone explain this to me? Similar situation in below tutorial from CodeProject:
http://www.codeproject.com/Articles/165368/WPF-MVVM-Quick-Start-Tutorial
We have a Song Class
public class Song
{
#region Members
string _artistName;
string _songTitle;
#endregion
#region Properties
/// The artist name.
public string ArtistName
{
get { return _artistName; }
set { _artistName = value; }
}
/// The song title.
public string SongTitle
{
get { return _songTitle; }
set { _songTitle = value; }
}
#endregion
}
And we have of course View Model for this class:
public class SongViewModel
{
Song _song;
public Song Song
{
get
{
return _song;
}
set
{
_song = value;
}
}
public string ArtistName
{
get { return Song.ArtistName; }
set { Song.ArtistName = value; }
}
}
And again, this part of code is something that I can't understand:
public class SongViewModel
{
Song _song;
public Song Song
What this "Song _song;" is? This is object of Song Class? And this Property "Song Song" is also wierd... Probably I have a lack of knowledge