/// <summary> /// The following was a homework project from IAmTimCorey's 'Project Type' paid series. Below is a fairly good example of how to pass data from Classes /// Within Class Libraries to the actual application. Everything here is coded in .NET Standard. /// </summary> /// <param name="args"></param> // This is the actual application static void Main(string[] args) { Console.WriteLine("Account Signup:\n\nPlease enter your Title (Mr/Ms/Dr/Etc):"); string prefix = Console.ReadLine(); Console.WriteLine("Please enter your First Name"); string firstName = Console.ReadLine(); Console.WriteLine("Please enter your Middle Name"); string middleName = Console.ReadLine(); Console.WriteLine("Please enter your Last Name"); string lastName = Console.ReadLine(); Console.WriteLine("Please enter your Suffix (Jr/Sr/MD/Esq)"); string suffix = Console.ReadLine(); // The 'Replace' part of this line can (and should) be deleted // because it takes place in the 'MethodsClass' class in the ConsoleMethodStandardLibrary string fullName = ($"{ prefix } { firstName } { middleName } { lastName } { suffix }").Replace(" ", " "); // INSTANTIATE A CLASS FROM THE CLASS LIBRARY new HWConsumerLoginClass // Instantiate Consumer Login Class { Prefix = prefix, FirstName = firstName, MiddleName = middleName, LastName = lastName, Suffix = suffix }; Console.WriteLine("What are your favorite 2 numbers?"); Console.Write("Number 1: "); string x = Console.ReadLine(); Console.Write("Number 2: "); string y = Console.ReadLine(); int intx = Convert.ToInt32(x); int inty = Convert.ToInt32(y); // INSTANTIATE THE CLASS FROM THE CLASS LIBRARY THAT HAS THE METHODS IN IT // Removes unnessecary spaces from the user-input strings. MethodsClass methodsClass = new MethodsClass { }; // Instantiate and name class Console.WriteLine($"Your full name is: {methodsClass.RemoveSpaces(fullName)}\n and " + // Calls MethodsClass method to remove spaces $"the sum of the numbers you entered is: {methodsClass.AddNumbers(intx, inty)}"); // Calls MethodsClass to add numbers }
public IHttpActionResult Order(OrderViewModel order) { try { using (DatabaseContext dbctx = new DatabaseContext()) { var recipList = RecipeManagementHelper.GetAllRecipes(); RecipeViewModel recipe = recipList.Find(recip => recip.RecipeName == order.Recipe); if (recipe.RecipeName.Equals(order.Recipe)) { var Ingredients = recipe.Ingredients; if (OrdersManagementHelper.OrderValidation(Ingredients, order.Amount).ElementAt(0).Key.Equals("true")) { var NewIngredients = OrdersManagementHelper.ExtractIngredients(Ingredients, order.Amount); RecipeViewModel NewRecipe = new RecipeViewModel(recipe.RecipeName, NewIngredients, recipe.Actions); OrdersManagementHelper.AddOrder(order); var idOrder = dbctx.Orders.Where(ord => ord.Recipe.Equals(order.Recipe)) .Where(ord => ord.Amount.Equals(order.Amount)) .Select(column => column.ID_order) .ToList(); MethodsClass mc = new MethodsClass(); string s = RecipeManagementHelper.ParseObjectToStringForMSMQ(NewRecipe).ToString(); mc.SendMessage(s); LoggerHelper.Order(" a fost finalizata cu succes cu id-ul ", idOrder.LastOrDefault().ToString() + ". " + order.Amount + " produse <" + order.Recipe + "> au fost create cu succes."); LoggerHelper.Products(order.Amount); return(Ok("SUCCESS")); } else { LoggerHelper.Order(" a fost finalizata cu eroare.", ""); return(Ok(OrdersManagementHelper.OrderValidation(Ingredients, order.Amount))); } } else { return(NotFound()); } } } catch (InvalidOperationException e) { Console.WriteLine("Exception in OrdersManagementControllere/api/Order", e.ToString()); return(NotFound()); } }
private string ClassAndStructTest(out string str2) { //DateTimeList为自定义的一个类型,见引用部分,其类型为List<T> DateTimeList dtl = new DateTimeList(); //逆变协变的使用 Func <Object, ArgumentException> fn1 = null; Func <string, Exception> fn2 = fn1; //可空值类型 //若不为可空值类型,则其值不可为null Nullable <int> nullX = 3; int? nullY = 4; nullX = null; //当左边不为null,则等于左边,否则等于右边 int?nullZ = nullX ?? nullY; nullY = nullX; nullZ = nullX ?? nullY ?? 5; try { Member m = new Member() { Nage = "123", Age = 5 - 3 }; } catch (System.ArgumentOutOfRangeException ex) { MessageBox.Show(ex.Message); } //匿名类型 var o1 = new { Name = "123", Age = -3, Sex = "F" }; someClass sc = new someClass(); someClass sc2 = new someClass(); someStruct ss = new someStruct(); someStruct ss2 = new someStruct(); sc.x = 3; sc2 = sc; sc.x = 5; ss.x = 4; ss2 = ss; ss.x = 6; object o = ss.x; someStruct ss3 = new someStruct(); someClass sc3 = new someClass(); ss3.x = (int)o; sc3.x = (int)o; ss.x = 7; o = 9; int j = 3; int k = 9; if (j == k) { } MethodsClass.SetDouble(ref j); Swap(ref k, ref j); Test1 <string> t1 = new Test1 <string>(); ITest1 <string> t2 = t1; string t1r = t1.TestIMethod(); string t2r = t2.TestIMethod(); string str1 = @"/// <summary> /// 引用类型,在内存中,传递指针 /// </summary> class someClass { public int x; } /// <summary> /// 在线程栈中,复制值 /// </summary> struct someStruct { public int x; } someClass sc = new someClass(); someClass sc2 = new someClass(); someStruct ss = new someStruct(); someStruct ss2 = new someStruct(); sc.x = 3; sc2 = sc; sc.x = 5; ss.x = 4; ss2 = ss; ss.x = 6; object o = ss.x; someStruct ss3 = new someStruct(); someClass sc3 = new someClass(); ss3.x = (int)o; sc3.x = (int)o; ss.x = 7 o = 9; int j = 3; int k = 9; SetDouble(ref j); Swap(ref k, ref j); ===================================================================== "; str2 = "sc=" + sc.x + "\n" + "sc2=" + sc2.x + "\n" + "ss=" + ss.x + "\n" + "ss2=" + ss2.x + "\n"; str2 += "ss3=" + ss3.x + "\nsc3=" + sc3.x + "\no=" + o + "\nj.Triple()=" + j.Triple() + "\n"; str2 += DisplayTypes(3, "ss", o, j, k, null); string a = null; //若a为空,则将x赋值给b string b = a ?? "x"; return(str1); }
public void Test1() { var methods = new MethodsClass(); Assert.Equal(4, methods.Add(2, 2)); }