using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BInnovitec.Abstract
{
//refrence from java2s.com
class Program
{
static void Main(string[] args)
{
CompleExampleOfArrayListWithDictionary();
// AbstractFunction();
// AggregateProgram();
// ConvertArrayToDictionary();
Console.ReadLine();
}
private static void ConvertArrayToDictionary()
{
var employeeRecord = new[] {
new {Name="Rajesh",Age=12,Branch="CS"},
new {Name="Girijesh",Age=23,Branch="ME"},
new {Name="Mahesh",Age=24,Branch="EC"}};
var employeeDictionary = employeeRecord.ToDictionary(employeeKey => employeeKey.Name);
Console.WriteLine("{0} age is :{1} and branch is:{2}", employeeDictionary["Girijesh"].Name, employeeDictionary["Girijesh"].Age, employeeDictionary["Girijesh"].Branch);
}
private static void CompleExampleOfArrayListWithDictionary()
{
Dictionary<int, Employee> employeeArrayDataRecord = Employee.GetEmployeeArray().ToDictionary(k => k.rollNumber);
foreach (var emp in employeeArrayDataRecord)
{
Console.WriteLine(emp.Value.name+""+emp.Value.branch+""+emp.Value.rollNumber);
}
}
public class Employee
{
public int rollNumber { get; set; }
public string name { get; set; }
public string branch { get; set; }
public static ArrayList GetEmployeeArrayList()
{
ArrayList alEmployee = new ArrayList();
alEmployee.Add(new Employee { rollNumber = 1, name = "Girijesh", branch = "CS" });
alEmployee.Add(new Employee { rollNumber = 2, name = "Srijesh", branch = "ME" });
return alEmployee;
}
public static Employee[] GetEmployeeArray()
{
//their are 2methods defined here use anyone.
return (GetEmployeeArrayList().Cast<Employee>().ToArray());
//return ((Employee[])GetEmployeeArrayList().ToArray(typeof(Employee)));
}
}
private static void AggregateProgram()
{
int number = 4;
IEnumerable<int> sequenceNumber = Enumerable.Range(1, number);
foreach (var item in sequenceNumber)
{
Console.WriteLine(item);
}
// int[] sequenceNumber = {1,2,3,4,5 };
var result = sequenceNumber.Aggregate((a, b) => a * b);
Console.WriteLine("1*2*..*number = {0} ", result);
result = sequenceNumber.Aggregate(0, (p, q) => p + q);
Console.WriteLine("1+2+..+number = {0} ", result);
var testResult = from m in typeof(int).GetMethods()
group m by m.Name into gBy
select gBy;
Dictionary<string, int> myDictionary = testResult.ToDictionary(k => k.Key, k => k.Count());
foreach (var item in myDictionary)
{
Console.WriteLine("The key is:{0} and value is:{1}", item.Key, item.Value);
}
}
private static void AbstractFunction()
{
MotorVehicle mvc = new MotorVehicle("BMW", "$10008");
mvc.ShowNameAndPrice();
}
}
public class MotorVehicle : Vehicle
{
public MotorVehicle(string name, string price)
: base(name, price)
{
//ToDO
}
public override void ShowNameAndPrice()
{
Console.WriteLine("The name of Car is :{0} and price tag ={1} ");
Console.WriteLine(nameV + "" + priceV);
}
}
public abstract class Vehicle
{
public string nameV;
public string priceV;
public Vehicle(string name, string price)
{
// TODO: Complete member initialization
this.nameV = name;
this.priceV = price;
}
public abstract void ShowNameAndPrice();
}
}
=================================================
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BInnovitec.Abstract
{
//refrence from java2s.com
public class Program
{
static void Main(string[] args)
{
#region Using constructor
ArrayList list = new ArrayList();
list.Add(new Instrument("computer", 12.23, 2));
list.Add(new Instrument("printer", 2.23, 4));
foreach (var item in list)
{
Console.WriteLine(item);
}
#endregion
Console.ReadKey();
}
}
public class Instrument
{
public string name { get; set; }
public double cost { get; set; }
public int quantity { get; set; }
public Instrument(string itemName, double money, int number)
{
this.name = itemName;
this.cost = money;
this.quantity = number;
}
public override string ToString()
{
return String.Format("{0,-10}Cost: {1,6:C} Quantity: {2}", name, cost, quantity);
}
}
}
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BInnovitec.Abstract
{
//refrence from java2s.com
public class Program
{
static void Main(string[] args)
{
#region Using constructor
ArrayList list = new ArrayList();
list.Add(new Instrument("computer", 12.23, 2));
list.Add(new Instrument("printer", 2.23, 4));
foreach (var item in list)
{
Console.WriteLine(item);
}
#endregion
Console.ReadKey();
}
}
public class Instrument
{
public string name { get; set; }
public double cost { get; set; }
public int quantity { get; set; }
public Instrument(string itemName, double money, int number)
{
this.name = itemName;
this.cost = money;
this.quantity = number;
}
public override string ToString()
{
return String.Format("{0,-10}Cost: {1,6:C} Quantity: {2}", name, cost, quantity);
}
}
}
No comments:
Post a Comment