static void Main(string[] args) { StudentC studentC = new StudentC(); studentC.Name = "Jane"; ByValueTestClass(studentC); // passed by ref Console.WriteLine(studentC.Name); // Prints - Jane-ByValue ByReferenceTestClass(ref studentC); // passed by ref - ref keyword is redundant Console.WriteLine(studentC.Name); // Prints - Jane-ByValue-ByReference //-- StudentS studentS = new StudentS(); studentS.Name = "John"; ByValueTestStruct(studentS); // passed by value Console.WriteLine(studentS.Name); // Prints - John ByReferenceTestStruct(ref studentS); // passed by ref Console.WriteLine(studentS.Name); // Prints - John-ByReference //- Console.ReadKey(); }
public ActionResult Update(StudentS s) { try { Student st = new Student() { CardID = s.CardID, Address = "", Borndate = DateTime.Now, ClassID = Convert.ToInt32(s.ClassName), Email = "", Gender = false, Phone = "", CreateTime = DateTime.Now, StudentName = s.StudentName, Password = s.Password, Shan = false, StudentID = s.StudentID }; ef.Entry(st).State = EntityState.Modified; if (ef.SaveChanges() > 0) { return(Content("修改成功")); } return(Content("")); } catch (Exception ex) { return(Content("身份证号已经存在了")); } }
public ActionResult ADD(StudentS s) { try { ef.Configuration.EnsureTransactionsForFunctionsAndCommands = false; if (ef.Students.Any(x => x.CardID == s.CardID.Trim())) { if (ef.Students.FirstOrDefault(x => x.CardID == s.CardID && x.Shan == true) != null) { Student tae = ef.Students.FirstOrDefault(x => x.CardID == s.CardID); tae.StudentName = s.StudentName; tae.Shan = false; tae.ClassID = Convert.ToInt32(s.ClassName); tae.Password = s.Password; ef.Entry(tae).State = EntityState.Modified; if (ef.SaveChanges() > 0) { return(Content("增加成功")); } } else { return(Content("已经存在了")); } } else { Student st = new Student() { CardID = s.CardID, Address = "", Borndate = DateTime.Now, ClassID = Convert.ToInt32(s.ClassName), Email = "", Gender = false, Phone = "", CreateTime = DateTime.Now, StudentName = s.StudentName, Password = s.Password, Shan = false, }; ef.Entry(st).State = EntityState.Added; if (ef.SaveChanges() > 0) { return(Content("增加成功")); } } return(Content("失败")); } catch (Exception ex) { return(Content(ex.ToString())); } }
public static void StudentSByEmail() { var input = Console.ReadLine(); var students = new List <StudentS>(); while (!input.Equals("END")) { var studentInfo = input.Split(); var firstName = studentInfo[0]; var lastName = studentInfo[1]; var email = studentInfo[2]; var currentStudent = new StudentS(firstName, lastName, email); students.Add(currentStudent); input = Console.ReadLine(); } students.Where(s => s.Email.EndsWith("@gmail.com")).ToList().ForEach(s => Console.WriteLine($"{s.FirstName} {s.LastName}")); }
public static void StudentsByPhone() { var input = Console.ReadLine(); var students = new List <StudentS>(); while (!input.Equals("END")) { var studentInfo = input.Split(); var firstName = studentInfo[0]; var lastName = studentInfo[1]; var phone = studentInfo[2]; var currentStudent = new StudentS(firstName, lastName, phone); students.Add(currentStudent); input = Console.ReadLine(); } students.Where(s => s.Email.StartsWith("02") || s.Email.StartsWith("+3592")).ToList().ForEach(s => Console.WriteLine($"{s.FirstName} {s.LastName}")); }
public string ReadAll() { SchoolEntity school = new SchoolEntity(); List <StudentS> studentS = new List <StudentS>(); StudentS stu = null; foreach (var s in school.Students) { stu = new StudentS { IdStudent = s.StudentId, NameStudent = s.StudentName }; studentS.Add(stu); } string jsonStudents = JsonConvert.SerializeObject(studentS); return(jsonStudents); }
static void ByValueTestStruct(StudentS student) { student.Name += "-ByValue"; }
static void ByReferenceTestStruct(ref StudentS student) { student.Name += "-ByReference"; }