Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
School/C# - Beginner (Denis)/Lesson 67/lesson_67.cs
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
114 lines (98 sloc)
2.04 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Person | |
{ | |
public string Name { get; init; } | |
public int Age { get; set; } | |
} | |
using System; | |
namespace HelloApp | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var person = new Person(); | |
person.Name = "John Smith"; // Ошибка | |
Console.WriteLine(person.Name); | |
} | |
} | |
public class Person | |
{ | |
public string Name { get; init; } | |
public int Age { get; set; } | |
} | |
} | |
var person = new Person(); | |
person.Name = "John Smith"; // Ошибка | |
using System; | |
namespace HelloApp | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var person = new Person() { Name = "Tom" }; | |
Console.WriteLine(person.Name); // Tom | |
} | |
} | |
public class Person | |
{ | |
public string Name { get; init; } | |
} | |
} | |
using System; | |
namespace HelloApp | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var person = new Person("Bob"); | |
Console.WriteLine(person.Name); // Bob | |
} | |
} | |
public class Person | |
{ | |
public Person(string name) | |
{ | |
Name = name; | |
} | |
public string Name { get; init; } | |
public int Age { get; set; } | |
} | |
} | |
using System; | |
namespace HelloApp | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var person = new Person() { Name = "Sam" }; | |
Console.WriteLine(person.Name); // Sam | |
Console.WriteLine(person.Email); // Sam@gmail.com | |
} | |
} | |
public class Person | |
{ | |
readonly string name; | |
public string Name | |
{ | |
get { return name; } | |
init | |
{ | |
name = value; | |
Email = $"{value}@gmail.com"; | |
} | |
} | |
public string Email { get; init; } | |
} | |
} | |
public class Person | |
{ | |
public Person(string n) | |
{ | |
Name = n; | |
} | |
public string Name { get; } | |
} | |
var person = new Person() { Name = "Sam" }; // ! Ошибка |