Got two inputs namely name,dept from the user.
Have to call the method empreg in the program class and store the details using emplist object and print the data in screen.
How to do it?
Employee.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace fundamentals
{
public class Employee
{
private string name;
private string dept;
public string Name
{
get { return this.name; }
set { this.name = value; }
}
public string Dept
{
get { return this.dept; }
set { this.dept = value; }
}
}
}
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace fundament
{
public class Program
{
public Employee[] empList = new Employee[2];
string ename;
string edept;
Console.WriteLine("Name :");
ename = Console.ReadLine();
Console.WriteLine("Dept :");
edept = Console.ReadLine();
public object empreg(string name, string dept)
{
}
}
}
Related
I am trying to build custom DLL which puts a particular key to Redis key-value storage. I builds, executes, but doesnt do anything. No key added. This is my code so far:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using TSLab.Script;
using TSLab.Script.Handlers;
using StackExchange.Redis;
namespace TSLab.pmus
{
[HandlerCategory("Redis")]
[InputsCount(2)]
public class WriteToRedis : ITwoSourcesHandler, ISecurityInput0, IDoubleInputs, IDoubleReturns, IStreamHandler, IValuesHandlerWithNumber, IContextUses
{
private ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost");
public IContext Context { set; private get; }
[HandlerParameter(Name = "table", NotOptimized = true)]
public int table { get; set; }
[HandlerParameter(Name = "key", Default = "mykey", NotOptimized = true)]
public string key { get; set; }
public IList<double> Execute(ISecurity sec, params IList<double>[] dataArr)
{
return new double[0];
}
public double Execute(ISecurity sec, ConnectionMultiplexer redis, params double[] dataArr)
{
IDatabase db = redis.GetDatabase(table);
db.StringSet("testKey", "Test string");
return 0;
}
}
}
As #MarcGravell said, the problem was in two 'Execute' methods.
I changed code to:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using TSLab.Script;
using TSLab.Script.Handlers;
using StackExchange.Redis;
namespace TSLab.pmus
{
[HandlerCategory("Redis")]
[InputsCount(2)]
public class WriteToRedis : ITwoSourcesHandler, ISecurityInput0, IDoubleInputs, IDoubleReturns, IStreamHandler, IValuesHandlerWithNumber, IContextUses
{
private ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost");
public IContext Context { set; private get; }
[HandlerParameter(Name = "table", NotOptimized = true)]
public int table { get; set; }
[HandlerParameter(Name = "key", Default = "mykey", NotOptimized = true)]
public string key { get; set; }
public IList<double> Execute(ISecurity sec, params IList<double>[] dataArr)
{
IDatabase db = redis.GetDatabase(table);
db.StringSet("testKey", "Test string");
return new double[0];
}
}
}
And now it works fine.
The Program Works very well and produces output when I try to evaluate it throws me this error "Error in implementation. Exception has been thrown by the target of an invocation."
What to do with this. Can anyone help me
Write a program to find the vehicles released between certain year.
\\class Vehicle
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LinqApp1
{
public class Vehicle
{
public String VehicleId{get; set; }
public String VehicleName{ get; set; }
public String Brand { get; set; }
public int ReleaseYear { get; set; }
public Vehicle(String vehicleId, String vehicleName, String brand,int releaseYear)
{
this.VehicleId = vehicleId;
this.VehicleName = vehicleName;
this.Brand = brand;
this.ReleaseYear = releaseYear;
}
}
}
\\class Program
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
namespace LinqApp1 //DO NOT CHANGE the namespace name
{
public class Program //DO NOT CHANGE the class name
{
/** DO NOT CHANGE this 'List' declaration with initialized values **/
public static List<Vehicle> VehicleList = new List<Vehicle>()
{
new Vehicle("HO345","CRV","Honda",2015),
new Vehicle("HY562","Creta","Hyundai",2017),
new Vehicle("RE198","Duster","Reanult",2014),
new Vehicle("MA623","Spacio","Suzuki",2014),
new Vehicle("TR498","Nexon","Tata",2015),
new Vehicle("TR981","Zest","Tata",2016),
new Vehicle("HO245","WRV","Honda",2018)
};
static void Main(string[] args) //DO NOT Change this 'Main' signature
{
//Implement your code here
//Vehicle v = new Vehicle();
Console.WriteLine("Enter From Year:");
int fromYear = int.Parse(Console.ReadLine());
Console.WriteLine("Enter To Year:");
int toYear = int.Parse(Console.ReadLine());
GetVehicleName(fromYear,toYear);
}
//Implement the method 'GetVehicleName' here
public static void GetVehicleName(int fromYear, int toYear)
{
IEnumerable<Vehicle> vehicles = from vehicle in VehicleList where vehicle.ReleaseYear >= fromYear && vehicle.ReleaseYear <= toYear select vehicle;
Console.WriteLine("Vehicle Name Released Between {0} And {1}",fromYear,toYear);
foreach(Vehicle v in vehicles)
{
Console.WriteLine(v.VehicleName);
}
}
/** DO NOT CHANGE this ParameterExpression **/
public static ParameterExpression variableExpr = Expression.Variable(typeof(IEnumerable<Vehicle>), "sampleVar");
public static Expression GetMyExpression(int fromYear, int toYear)
{
Expression assignExpr = Expression.Assign(variableExpr,Expression.Constant(from vehicle in VehicleList where vehicle.ReleaseYear >= fromYear && vehicle.ReleaseYear <= toYear select vehicle.VehicleName/**copy the Linq query from the above method 'GetVehicleName' and paste it here**/));
return assignExpr;
}
}
}
This is the sample input/output
Enter From Year: 2014
Enter To Year: 2016
Vehicle Name Released Between 2014 And 2016
Duster
Spacio
CRV
Nexon
Zest
Try this below Query,
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LinqApp1
{
public class Vehicle
{
public String VehicleId{get; set; }
public String VehicleName{ get; set; }
public String Brand { get; set; }
public int ReleaseYear { get; set; }
public Vehicle(String vehicleId, String vehicleName, String brand,int releaseYear)
{
this.VehicleId = vehicleId;
this.VehicleName = vehicleName;
this.Brand = brand;
this.ReleaseYear = releaseYear;
}
}
}
\\class Program
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
namespace LinqApp1 //DO NOT CHANGE the namespace name
{
public class Program //DO NOT CHANGE the class name
{
/** DO NOT CHANGE this 'List' declaration with initialized values **/
public static List<Vehicle> VehicleList = new List<Vehicle>()
{
new Vehicle("HO345","CRV","Honda",2015),
new Vehicle("HY562","Creta","Hyundai",2017),
new Vehicle("RE198","Duster","Reanult",2014),
new Vehicle("MA623","Spacio","Suzuki",2014),
new Vehicle("TR498","Nexon","Tata",2015),
new Vehicle("TR981","Zest","Tata",2016),
new Vehicle("HO245","WRV","Honda",2018)
};
Public void Main(string[] args) //DO NOT Change this 'Main' signature
{
//Implement your code here
//Vehicle v = new Vehicle();
Console.WriteLine("Enter From Year:");
int fromYear = int.Parse(Console.ReadLine());
Console.WriteLine("Enter To Year:");
int toYear = int.Parse(Console.ReadLine());
GetVehicleName(fromYear,toYear);
}
//Implement the method 'GetVehicleName' here
public static void GetVehicleName(int fromYear, int toYear)
{
var vehicles = (from vehicle in VehicleList where vehicle.ReleaseYear >= fromYear && vehicle.ReleaseYear <= toYear select vehicle).ToList().OrderBy(x=>x.ReleaseYear);
Console.WriteLine("Vehicle Name Released Between {0} And {1}",fromYear,toYear);
foreach(Vehicle v in vehicles.ToList())
{
Console.WriteLine(v.VehicleName);
}
}
}
}
This is the sample input/output
Enter From Year: 2014
Enter To Year: 2016
Vehicle Name Released Between 2014 And 2016
Duster
Spacio
CRV
Nexon
Zest
I'm creating a Xamarin.Forms Portable Application wherein I was able to display a Pie Chart using OxyPlot. My chart only has pre-defined items. What I want to do is to make the items from my DATABASE in Visual Studio to be displayed on the Chart and not the pre-defined items.
I have 2 projects in one Solution. The WebFormsProject and the Xamarin.Forms (Portable)
In my WebFormsProject, I created a SalesController where I used LINQ expression to get all the data in the database that I need. I also created a SalesViewModel there where I have declared all the Properties I have. I tried to test it in my WEB API if it does return a value or not, and IT DOES RETURN A VALUE.
In my PORTABLE project, I have a created Sales model that has exactly the same Properties with my SalesViewModel in the WebFormsProject. I also have a SalesVM.cs wherein I tried to access the records from the WebFormsProject by using SalesServices and RestClient.
I have tried using these codes but it didn't work. What do you think is the reason behind this?
Here are my codes:
WebForms
1.) SalesViewModel.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace WebFormsDemo.ViewModel
{
public class SalesViewModel
{
public int Id { get; set; }
public int ORDER_ID { get; set; }
public int ORDER_DETAILS_ID { get; set; }
public int PRODUCT_ID { get; set; }
public string PRODUCT_CODE { get; set; }
public string NET_AMOUNT { get; set; }
}
}
2.) SalesController.cs
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.Http.Description;
using WebFormsDemo;
using WebFormsDemo.ViewModel;
namespace WebFormsDemo.Controllers
{
public class SalesController : ApiController
{
private EBMSEntities db = new EBMSEntities();
// GET: api/Sales
public IQueryable<SalesViewModel> GetSalesViewModels()
{
//return db.SalesViewModels;
var sales = from order in db.ORDERs
join order_detail in db.ORDER_DETAILS
on order.ORDER_ID equals order_detail.ORDER_ID
join prod in db.PRODUCTs
on order_detail.PRODUCT_ID equals prod.PRODUCT_ID
orderby order_detail.TOTAL_AMT_PER_ITEM descending
//group prod by prod.PRODUCT_CODE
group order_detail by prod.PRODUCT_CODE into od
select new SalesViewModel
{
PRODUCT_CODE = od.Key,
NET_AMOUNT = od.Sum(p => p.TOTAL_AMT_PER_ITEM).ToString(),
};
return sales;
}
// GET: api/Sales/5
[ResponseType(typeof(SalesViewModel))]
public IHttpActionResult GetSalesViewModel(int id)
{
SalesViewModel salesViewModel = db.SalesViewModels.Find(id);
if (salesViewModel == null)
{
return NotFound();
}
return Ok(salesViewModel);
}
// PUT: api/Sales/5
[ResponseType(typeof(void))]
public IHttpActionResult PutSalesViewModel(int id, SalesViewModel salesViewModel)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
if (id != salesViewModel.Id)
{
return BadRequest();
}
db.Entry(salesViewModel).State = EntityState.Modified;
try
{
db.SaveChanges();
}
catch (DbUpdateConcurrencyException)
{
if (!SalesViewModelExists(id))
{
return NotFound();
}
else
{
throw;
}
}
return StatusCode(HttpStatusCode.NoContent);
}
// POST: api/Sales
[ResponseType(typeof(SalesViewModel))]
public IHttpActionResult PostSalesViewModel(SalesViewModel salesViewModel)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
db.SalesViewModels.Add(salesViewModel);
db.SaveChanges();
return CreatedAtRoute("DefaultApi", new { id = salesViewModel.Id }, salesViewModel);
}
// DELETE: api/Sales/5
[ResponseType(typeof(SalesViewModel))]
public IHttpActionResult DeleteSalesViewModel(int id)
{
SalesViewModel salesViewModel = db.SalesViewModels.Find(id);
if (salesViewModel == null)
{
return NotFound();
}
db.SalesViewModels.Remove(salesViewModel);
db.SaveChanges();
return Ok(salesViewModel);
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
db.Dispose();
}
base.Dispose(disposing);
}
private bool SalesViewModelExists(int id)
{
return db.SalesViewModels.Count(e => e.Id == id) > 0;
}
}
}
.
XamarinFormsPortable
1.) Sales.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace XamarinFormsDemo.Models
{
public class Sales
{
public int Id { get; set; }
public int ORDER_ID { get; set; }
public int ORDER_DETAILS_ID { get; set; }
public int PRODUCT_ID { get; set; }
public string PRODUCT_CODE { get; set; }
public double NET_AMOUNT { get; set; }
}
}
2.) SalesVM.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OxyPlot;
using OxyPlot.Series;
using OxyPlot.Xamarin.Forms;
using Xamarin.Forms;
using System.Runtime.CompilerServices;
using XamarinFormsDemo.Models;
using System.Collections.ObjectModel;
using XamarinFormsDemo.Services;
namespace XamarinFormsDemo.ViewModels
{
public class SalesVM
{
private List<Sales> salesmodel { get; set; }
public List<Sales> SalesModelvm
{
get
{
return salesmodel;
}
set
{
salesmodel = value;
OnPropertyChanged();
}
}
public SalesVM()
{
InitializeDataAsync();
}
private async Task InitializeDataAsync()
{
var salesServices = new SalesServices();
SalesModelvm = await salesServices.GetSalesAsync();
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
var handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}
3.) SalesServices.cs
using Plugin.RestClient;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XamarinFormsDemo.Models;
namespace XamarinFormsDemo.Services
{
public class SalesServices
{
public async Task<List<Sales>> GetSalesAsync()
{
RestClient_Sales<Sales> restClient = new RestClient_Sales<Sales>();
var salesList = await restClient.GetSalesAsync();
return salesList;
}
}
}
4.) RestClient.cs
public class RestClient_Sales<T>
{
private const string WebServiceUrl = "http://localhost:50857/api/Sales/";
public async Task<List<T>> GetSalesAsync()
{
var httpClient = new HttpClient();
var json = await httpClient.GetStringAsync(WebServiceUrl);
var taskModels = JsonConvert.DeserializeObject<List<T>>(json);
return taskModels;
}
}
I followed the article here and the sample code given in it.
What I am trying to implement is pretty straightfoward. I do have a fair understanding about collections and enumerators. However, what I don't understand is that even though there is hardly any difference in the way I have implemented the code as compared to how it is implemented in the given article, why I am getting an error.
Only difference in the implementation is that the sample code uses T (generic) whereas I am using a class named Address while implementing the custom Addresses collection class.
The code is pretty straightfoward. I have the following classes in the project.
Contact class
Addresses class (Implements custom collection and inherits from ICollection)
Address class
AddressEnumerator
What I wish to achieve is the Dataset like functionality where we can use a syntax like:
Dataset ds = new Dataset();
Ds.Tables[0]....blah blah blah.
I get a compile time error in the following method of the AddressEnumerator.cs class.
Error:
cannot apply indexing with [] to an expression of type ConsoleApplication2.Addresses (Addresses class implements an ICollection)
Compile time error occurs in the following statement:
_current = _collection[index];
public bool MoveNext()
{
if(++index >= _collection.Count)
{
return false;
}
else
{
_current = _collection[index];
}
return true;
}
Source code:
//following code snippet does not traverse the collection
foreach (Address a in c.Addresses)
{
Console.WriteLine(a.Street);
}
Program.cs
using System;
using System.Configuration;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
//RenderTimeSheet();
Address ad = new Address();
ad.Street = "Hollywood";
ad.City = "LA";
ad.State = "California";
ad.ZipCode = "93494";
ad.Country = "USA";
using (Contact c = new Contact(ad))
{
c.FirstName = "John";
c.LastName = "Doe";
Console.WriteLine(c.FirstName);
Console.WriteLine(c.LastName);
foreach (Address a in c.Addresses)
{
Console.WriteLine(a.Street);
}
}
Console.ReadKey();
}
}
Contact.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
namespace ConsoleApplication2
{
public class Contact : IDisposable
{
public string FirstName { get; set; }
public string LastName { get; set; }
public Addresses Addresses { get; set; }
public Contact(Address a)
{
Addresses = new Addresses(a);
}
public Contact()
{
}
public void Dispose()
{
Console.Write("Disposing off...");
}
}
}
Addresses.cs
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication2
{
public class Addresses : ICollection<Address>
{
private IList<Address> _lstAddress;
protected bool _IsReadOnly;
public Addresses(Address _a)
{
_lstAddress = new List<Address>();
}
public void Add(Address item)
{
_lstAddress.Add(item);
}
public void Clear()
{
_lstAddress.Clear();
}
public bool Contains(Address item)
{
foreach(Address a in _lstAddress)
{
if(a.Street == item.Street)
{
return true;
}
}
return false;
}
public void CopyTo(Address[] array, int arrayIndex)
{
throw new Exception("Not valid for this implementation.");
}
public int Count
{
get { return _lstAddress.Count; }
}
public bool IsReadOnly
{
get { return _IsReadOnly; }
}
public bool Remove(Address item)
{
bool result = false;
for (int i = 0; i < _lstAddress.Count; i++)
{
Address obj = (Address)_lstAddress[i];
if(obj.Street == item.Street)
{
_lstAddress.RemoveAt(i);
result = true;
break;
}
}
return result;
}
public IEnumerator<Address> GetEnumerator()
{
return new AddressEnumerator(this);
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
//throw new NotImplementedException();
return this.GetEnumerator();
}
}
}
Address.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication2
{
public class Address
{
public string Street { get; set; }
public string City { get; set; }
public string State { get; set; }
public string ZipCode { get; set; }
public string Country { get; set; }
}
}
AddressEnumerator.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
public class AddressEnumerator : IEnumerator<Address>
{
protected Addresses _collection;
protected int index;
protected Address _current;
public AddressEnumerator()
{
}
public AddressEnumerator(Addresses collection)
{
_collection = collection;
index = -1;
_current = default(Address);
}
public Address Current
{
get
{
return _current;
}
}
public void Dispose()
{
_collection = null;
_current = default(Address);
index = -1;
}
object System.Collections.IEnumerator.Current
{
get
{
return _current;
}
}
public bool MoveNext()
{
if(++index >= _collection.Count)
{
return false;
}
else
{
_current = _collection[index];
}
return true;
}
public void Reset()
{
throw new NotImplementedException();
}
}
}
this is a direct and short solution to your problem,
but it is not a "complete clean" solution, also the coding style of the complete implementation should be changed. there are more effective ways implementing enumerable interfaces ...
change the line
_current = _collection[index];
to
_current = _collection._lstAddress[index];
but you also need to change the access modifier
private IList<Address> _lstAddress
for example to
internal IList<Address> _lstAddress
The reason that the sample code works and yours doesn't is because the sample code class BusinessObjectCollection includes this:
public virtual T this[int index]
{
get
{
return (T)_innerArray[index];
}
set
{
_innerArray[index] = value;
}
}
which provides the subscript operator [] that your code lacks.
If you add that to your Addresses class (changing _innerArray to _lstAddress) then it should work, I think.
I got a code with a list which im trying to change to dictionary. my problem its that in 'BankRates.cs' i fail to add objects to my dictionary. i get error :no overload of method 'Add' takes 1 argument...can some explain why?? (i understand i should add a string to the function but when i try to add empty one to make it compile, the dictionary contains only one nonfunctional object)
i have this 4 cs files:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Converter
{
class Currency
{
//members
//getters and setters
public string Code { get; set; }
public string Name { get; set; }
public double Rate { get; set; }
public double Unit { get; set; }
public string Country { get; set; }
//constractor
public Currency(string code, string name, double rate, double unit, string country)
{
this.Code = code;
this.Name = name;
this.Rate = rate;
this.Unit = unit;
this.Country = country;
}
//override ToString method for visualization
public override string ToString()
{
return (Name + "-" +Code);
}
}
}
currencyDictionary:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Converter
{
class CurrencyDic
{
//setter and getter
public Dictionary<string,Currency> currencyDic { get; set; }
//constractor
public CurrencyDic()
{
currencyDic = new Dictionary<string,Currency>();
}
public CurrencyDic(Dictionary<string,Currency> cur)
{
currencyDic = new Dictionary<string,Currency>(cur);
}
// implements foreach
public IEnumerator<Currency> GetEnumerator()
{
foreach (Currency cur in currencyDic.Values) { yield return cur;}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Converter
{
interface IBankRates
{
void GetRates();
double Convert(Currency from, Currency to, double amount);
}
}
and the last one:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.IO;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Linq;
using System.Runtime.Remoting.Messaging;
namespace Converter
{
class BankRates:IBankRates
{
private string Bank_URL = "http://www.boi.org.il/currency.xml";
CurrencyDic currencyDic = new CurrencyDic();
public void GetRates()
{
XDocument xdoc = new XDocument();
try
{
xdoc = XDocument.Load(Bank_URL);}
catch (XmlException)
{
MessageBox.Show("Failed to load Xml file");
System.Environment.Exit(1);
}
//load the xml
var allCurencies = from currency in xdoc.Descendants("CURRENCY") //linq query
select new
{
Name = currency.Descendants("NAME").First().Value,
Unit = currency.Descendants("UNIT").First().Value,
Code = currency.Descendants("CURRENCYCODE").First().Value,
Cuntry = currency.Descendants("COUNTRY").First().Value,
Rate = currency.Descendants("RATE").First().Value
};
foreach (var currency in allCurencies)
{
currencyDic.currencyDic.Add(new Currency(currency.Code, currency.Name,
double.Parse(currency.Rate),
double.Parse(currency.Unit), currency.Cuntry));
}
}
//returns the list
public CurrencyDic getDic()
{
return currencyDic;
}
//makes the converting calculation
public double Convert(Currency from,Currency to, double amount)
{
double inRate, outRate, excangeRate;
inRate = from.Rate / from.Unit;
outRate = to.Rate / to.Unit;
excangeRate = inRate / outRate;
return (amount * excangeRate);
}
}
}