#include <iostream>
#include <stdexcept>
#include <iomanip>
using namespace std;
struct vantuz
{
vantuz& push();
vantuz& pull();
vantuz();
private:
bool pushed;
};
vantuz::vantuz():pushed(false)
{
}
vantuz& vantuz::push()
{
if(pushed)
{
throw logic_error("already pushed!");
}
pushed=!pushed;
cout<<"push! ";
return *this;
}
vantuz& vantuz::pull()
{
pushed=!pushed;
if(pushed)
{
throw logic_error("already pulled!");
}
cout<<"pull! ";
return *this;
}
int main()
{
try
{
vantuz v;
v.push().pull().push().pull().push().pull().push().push();
}
catch(logic_error& ex)
{
cout<<endl<<setw(20)<<setfill('@')<<' '<<"Runtime error!"<<setw(20)<<setfill('@')<<' '<<endl<<ex.what()<<endl;
throw;
}
return 0;
}
using System;
using System.Collections.Generic;
namespace ListKeyValuePair
{
class Program
{
public static void Main(string[] args)
{
List<KeyValuePair<string, string>> lkvp = new List<KeyValuePair<string, string>>();
lkvp.Add(new KeyValuePair<string,string>("pdo", "somedata"));
lkvp.Add(new KeyValuePair<string,string>("for", "somedata1"));
foreach (KeyValuePair<string, string> kvp in lkvp)
{
Console.WriteLine("Key= {0}, Value= {1}", kvp.Key, kvp.Value);
}
Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);
}
}
}
как можно сделать чтобы можно было вводить
data["for"]toString() чтобы возвращала somedata1
public static void Main(string[] args)
{
Dictionary<string, string> dictionary = new Dictionary<string, string>();
dictionary.Add("cat", "animal");
dictionary.Add("shark", "fish");
Console.WriteLine(dictionary["cat"]);
Console.ReadKey(true);
}
static QSqlDatabase* getPDB()
{
static QSqlDatabase *pdb = NULL;
if(pdb == NULL) {
pdb = connect();
}
return pdb;
}
<T>
, в твоем случае тип данных <Product>
).public interface IEnumerable<out T> : IEnumerable
<Product>
при обходе в цикле - ты сразу получаешь объект типа Product. Критическое мышление прививайте, тогда вопрос дезинформации и какой либо морали будет волновать вас гораздо меньше.