本文整理汇总了C#中Stock类的典型用法代码示例。如果您正苦于以下问题:C# Stock类的具体用法?C# Stock怎么用?C# Stock使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Stock类属于命名空间,在下文中一共展示了Stock类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: addTransaction
public void addTransaction(ApplicationDbContext db, ApplicationUser user, Stock stock, StockTransaction model)
{
model.StockTicker = stock.Identifier;
model.UserId = user.Id;
db.StockTransactions.Add(model);
db.SaveChanges();
}
示例2: ReturnsDateOfMostRecentEntry
public void ReturnsDateOfMostRecentEntry()
{
//// SETUP
// Test Data
var stock = new Stock { Ticker = "FLWS", CompanyName = "1-800 FLOWERS.COM" };
var oldest = new HistoricPrice { Stock = stock, Date = DateTime.Parse("1/1/2000") };
var middle = new HistoricPrice { Stock = stock, Date = DateTime.Parse("1/2/2000") };
var newest = new HistoricPrice { Stock = stock, Date = DateTime.Parse("1/3/2000") };
var testData = new List<HistoricPrice> { oldest, newest, middle };
// Create a mock generic repository.
var mockGenericRepository = new Mock<IReadOnlyRepository<HistoricPrice>>();
mockGenericRepository.Setup(mock => mock.FilterBy(It.IsAny<Expression<Func<HistoricPrice, bool>>>())).Returns(testData.AsQueryable());
// Setup target
var target = new ReadOnlyPriceHistoryRepository(mockGenericRepository.Object);
// EXECUTE
var actual = target.GetMostRecentDateForTicker(stock.Ticker);
// VERIFY
Assert.AreEqual(newest.Date, actual);
mockGenericRepository.Verify(mock => mock.FilterBy(It.IsAny<Expression<Func<HistoricPrice, bool>>>()), Times.Once());
}
开发者ID:TheLogansFerrySoftwareCo,项目名称:LF-Trading-Suite,代码行数:25,代码来源:ReadOnlyPriceHistoryRepostioryTests.cs
示例3: GetStock
public Stock GetStock(StockName stockName, DateTime startDate, DateTime endDate)
{
string dir = String.Format(@"..\..\StockData\Yahoo");
string filename = String.Format("{0}.stock", stockName);
var fullPath = Path.Combine(dir, filename);
List<IStockEntry> rates;
if (!File.Exists(fullPath))
{
rates = GetStockFromRemote(stockName, startDate, endDate);
Directory.CreateDirectory(dir);
using (Stream stream = File.Open(fullPath, FileMode.Create))
{
var bformatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
bformatter.Serialize(stream, rates);
}
}
else
{
using (Stream stream = File.Open(fullPath, FileMode.Open))
{
var bformatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
rates = (List<IStockEntry>) bformatter.Deserialize(stream);
}
}
var stock = new Stock(stockName, rates);
return stock;
}
示例4: RunExample
public void RunExample()
{
decimal price = 23.50m;
Stock stock = new Stock("MSFT", price);
Console.WriteLine("Stock set to {0:C}.", stock.Price);
Bidder bidderA = new Bidder("Bidder A", stock);
Bidder bidderB = new Bidder("Bidder B", stock);
Bidder bidderC = new Bidder("Bidder C", stock);
stock.Attach(bidderA);
stock.Attach(bidderB);
stock.Attach(bidderC);
price = 24.25m;
Console.WriteLine("\nStock set to {0:C}.", price);
stock.Price = price;
stock.Detach(bidderB);
Console.WriteLine("\n{0} detached.", bidderB.Name);
price = 26.75m;
Console.WriteLine("\nStock set to {0:C}.", price);
stock.Price = price;
}
示例5: Button2_Click
protected void Button2_Click(object sender, EventArgs e)
{
int id = Convert.ToInt32(DropDownList.SelectedValue);
int Quantity = Convert.ToInt32(QuantityBox.Text);
Stock newStock = new Stock(id, Quantity);
newStock.updateStock(id, Quantity);
}
示例6: Init
public void Init()
{
i1 = new StockItem ("BMAC56790", "Propelling Pencil", "Supply Master", "1.49", "10", "20");
stock_list = new Stock();
stock_list.AddStockItem(i1.StockCode, i1);
stock_control = new StockControl(stock_list);
}
示例7: Main
static void Main(string[] args)
{
Stock stock1 = new Stock("Technology", 160, 5, 15);
Stock stock2 = new Stock("Retail", 30, 2, 6);
Stock stock3 = new Stock("Banking", 90, 4, 10);
Stock stock4 = new Stock("Commodity", 500, 20, 50);
StockBroker b1 = new StockBroker("Broker 1");
b1.AddStock(stock1);
b1.AddStock(stock2);
StockBroker b2 = new StockBroker("Broker 2");
b2.AddStock(stock1);
b2.AddStock(stock3);
b2.AddStock(stock4);
StockBroker b3 = new StockBroker("Broker 3");
b3.AddStock(stock1);
b3.AddStock(stock3);
StockBroker b4 = new StockBroker("Broker 4");
b4.AddStock(stock1);
b4.AddStock(stock2);
b4.AddStock(stock3);
b4.AddStock(stock4);
}
示例8: initPublisher
private void initPublisher(String pub, int strength)
{
mgr = new DDSEntityManager("Ownership");
String partitionName = "Ownership example";
// create Domain Participant
mgr.createParticipant(partitionName);
// create Type
StockTypeSupport stkTS = new StockTypeSupport();
mgr.registerType(stkTS);
// create Topic
mgr.createTopic("OwnershipStockTracker");
// create Publisher
mgr.createPublisher();
// create DataWriter
mgr.createWriterWithStrength(strength);
dwriter= mgr.getWriter();
OwnershipDataWriter = dwriter as StockDataWriter;
msft = new Stock();
msft.ticker = "MSFT";
msft.publisher = pub;
msft.strength = strength;
msftHandle = OwnershipDataWriter.RegisterInstance(msft);
}
示例9: GetStock
public Stock GetStock(StockName stockName, DateTime startDate, DateTime endDate)
{
string dir = String.Format(@"..\..\StockData\Maya");
string filename = String.Format("{0}.csv", stockName);
var fullPath = Path.Combine(dir, filename);
var rates = new List<IStockEntry>();
var parser = new TextFieldParser(fullPath) {TextFieldType = FieldType.Delimited};
parser.SetDelimiters(",");
//skips the first 3 lines
parser.ReadFields();
parser.ReadFields();
parser.ReadFields();
while (!parser.EndOfData)
{
var fields = parser.ReadFields();
if (fields != null)
{
StockEntry stockEntry = null;
rates.Add(stockEntry);
}
}
rates.Reverse();
var stock = new Stock(stockName, rates);
return stock;
}
示例10: ReconcileStock
public ReconcileStock(int _id)
{
InitializeComponent();
id = _id;
sl = new StockList(id);
s = sl.ViewAStock(sl[0].StockID);
}
示例11: StockTest
public StockTest()
{
_stock = new Stock("MSFT");
_stock.CurrentPrice = 5.5m;
_purchase1 = new StockTransaction(DateTime.Now, 4.0m, 7);
_purchase2 = new StockTransaction(DateTime.Now.AddDays(-1), 7.5m, 2);
_sale1 = new StockTransaction(DateTime.Now, 5.0m, -1);
}
示例12: Main
static void Main()
{
Stock x = new Stock();
x.SetPreviousPrice(5.3);
Console.WriteLine(x.PreviousPrice); //=5.3
Console.WriteLine(x.Words[1]); //=quick
}
示例13: GetFristCol
public Stock GetFristCol(string data)
{
List<Price> prices = new List<Price>();
List<DataItem> items = new List<DataItem>();
string firstCol = string.Empty;
List<string> lines = data.Split('\n').ToList<string>();
for (int i = 2; i < lines.Count; i++)
{
string line = lines[i];
List<string> numStrs = line.Split(' ').ToList<string>();
if (numStrs.Count < 5)
continue;
DataItem item = new DataItem();
Price price = new Price();
price.content = new string[4];
for (int numI = 0; numI < numStrs.Count; numI++)
{
if (numI == 0)
item.content = numStrs[numI];
if (numI > 0 && numI < 5)
{
price.content[numI-1] = numStrs[numI];
if (numI == 3)
{
price.content[numI-1] = numStrs[numI+1];
}
if (numI == 4)
{
price.content[numI - 1] = numStrs[numI-1];
}
}
// if (numI > 0 && numI < 4)
//price.content += ",";
}
items.Add(item);
prices.Add(price);
}
Stock stock = new Stock();
stock.price = new Price[prices.Count];
for (int itemI = 0; itemI < items.Count; itemI++)
{
stock.data += items[itemI].content;
if (itemI != items.Count - 1)
stock.data += ",";
}
for (int priceI = 0; priceI < prices.Count; priceI++)
{
stock.price[priceI] = prices[priceI]; // += "[" + prices[priceI].content + "]";
//if (priceI != prices.Count - 2)
// stock.price += ";";
}
// stock.data = "[" + stock.data + "]";
// stock.price = "[" + stock.price + "]";
return stock;
}
示例14: ImportStock
public void ImportStock(Stock stock)
{
using (var context = ContainerHelper.Instance.Resolve<IRepositoryContext>())
{
//添加新的股票基础数据
context.UnitOfWork.RegisterNew<Stock>(stock);
context.UnitOfWork.Commit();
}
}
示例15: tstInheritance1
static void tstInheritance1()
{
Stock stock = new Stock { Name = "MSFT", SharesOwned = 1500 };
House house = new House { Name = "SAS", Mortgage = 2300 };
stock.Display();
house.Display();
//Upcasting
Stock stock2 = new Stock();
Asset asset = stock2;
Console.WriteLine((asset == stock2 ? "asset == stock2!" : "asset != stock2!"));
//asset.SharesOwned; - yet Stock fields aren't accessible!!!
//To access Stock fields DOWNCASTING is needed!!
Stock stock3 = (Stock) asset;
Console.WriteLine(stock3.SharesOwned); // <No error>
Console.WriteLine(stock3 == asset); // True
Console.WriteLine(stock3 == stock2); // True
//AS operator
Asset a = new Asset();
Stock s = a as Stock; // s is null; no exception thrown
try {
long shares1 = ((Stock)a).SharesOwned; // Approach #1
}
catch (InvalidCastException ice) {
Console.WriteLine(ice.ToString());
}
if (s != null) {
Console.WriteLine(s.SharesOwned);
long shares2 = (a as Stock).SharesOwned; // Approach #2
}
/*
* Another way of looking at it is that with the cast operator (Approach #1), you’re
saying to the compiler: “I’m certain of a value’s type; if I’m
wrong, there’s a bug in my code, so throw an exception!”
Whereas with the as operator (Approach #2), you’re uncertain of its type and
want to branch according to the outcome at runtime.
* */
//IS operator
if (a is Stock)
Console.WriteLine(((Stock)a).SharesOwned);
/*
* The is operator tests whether a reference conversion would succeed; in other words,
whether an object derives from a specified class (or implements an interface). It is
often used to test before downcasting.
* */
}