سلام بر تمامی برنامه نویسان #C 😉 در این مطلب از وب سایت پروگرم 98 کد ذخیره object های تعریف شده توسط کاربر در List collection در سی شارپ #C را آماده کردم. امیدوارم که این کد برای شما مفید باشد.
خروجی کد به این صورت می باشد :
Product list:
A Cost: $5.90 On hand: 3
B Cost: $8.20 On hand: 2
C Cost: $3.50 On hand: 4
D Cost: $1.80 On hand: 8
A Cost: $5.90 On hand: 3
B Cost: $8.20 On hand: 2
C Cost: $3.50 On hand: 4
D Cost: $1.80 On hand: 8
کد ذخیره object های تعریف شده توسط کاربر در List collection در سی شارپ #C :
using System;
using System.Collections.Generic;
class Product {
string name;
double cost;
int onhand;
public Product(string n, double c, int h) {
name = n;
cost = c;
onhand = h;
}
public override string ToString() {
return
String.Format("{0,-10}Cost: {1,6:C} On hand: {2}",
name, cost, onhand);
}
}
class MainClass {
public static void Main() {
List<Product> inv = new List<Product>();
using System.Collections.Generic;
class Product {
string name;
double cost;
int onhand;
public Product(string n, double c, int h) {
name = n;
cost = c;
onhand = h;
}
public override string ToString() {
return
String.Format("{0,-10}Cost: {1,6:C} On hand: {2}",
name, cost, onhand);
}
}
class MainClass {
public static void Main() {
List<Product> inv = new List<Product>();