|
|
in 매개 변수
|
|
// 여기서의 in은 ref readonly처럼 작동함 함수 call시에는 in을 쓰거나 말거나 동일 void PrintDate(in DateTime date) { Console.WriteLine(date); } |
null 관련 연산자
|
|
// 오래전 instance = instance == null ? value : instance; // 기존 instance = instance ?? value; // 현재 instance ??= value; |
Auto Property
|
|
// C# 6.0 Auto property public string Name { get; set; } = "Karu"; |
Index 연산
|
|
// C# 8.0 인덱스 연산 string str = "Rolling Ress"; var last = str[^1]; // 's' var sub = str[0..4]; // "Roll", 구간은 [0, 4) |
ICollection 사용
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
public ICollection<Student> m_listLandSiteDataText { get; set; } protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.AddColumn<int>( name: "CourseId", table: "Students", nullable: true); migrationBuilder.CreateIndex( name: "IX_Students_CourseId", table: "Students", column: "CourseId"); migrationBuilder.AddForeignKey( name: "FK_Students_Courses_CourseId", table: "Students", column: "CourseId", principalTable: "Courses", principalColumn: "CourseId", onDelete: ReferentialAction.Restrict); } |
Index와 ForeignKey 없이 생성
|
|
[ForeignKey("Course")] public int CourseId { get; set; } // 또는 [ForeignKey("CourseId")] public int CourseId { get; set; } protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.AddColumn<int>( name: "CourseId", table: "Students", nullable: false, defaultValue: 0); } |
virtual 사용시
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
public int CourseId { get; set; } [ForeignKey("CourseId")] public virtual Course m_mvLandSiteDataImage { get; set; } protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.AddColumn<int>( name: "CourseId", table: "Students", nullable: false, defaultValue: 0); migrationBuilder.CreateIndex( name: "IX_Students_CourseId", table: "Students", column: "CourseId"); migrationBuilder.AddForeignKey( name: "FK_Students_Courses_CourseId", table: "Students", column: "CourseId", principalTable: "Courses", principalColumn: "CourseId", onDelete: ReferentialAction.Cascade); } |
|
|
SqlConnection conn = new SqlConnection(conStr); SqlCommand cmd = new SqlCommand("sp_getdata", conn); cmd.Parameters.Add("@userIndex", SqlDbType.Int).Value = MemberNo; cmd.CommandType = CommandType.StoredProcedure; conn.Open(); SqlDataReader reader = cmd.ExecuteReader(); if (reader.Read()) { Fee = Convert.ToInt32(reader["Fee"].ToString()); } conn.Close(); |
|
링크
|