I learn programming oriented object, and I want to do this code but I got those problems, I think I don't really know the concept of virtual.
View image 1
Code:
class Joueur
{
private string _nom;
private string _prenom;
private DateTime _dateDeNaissance;
private string _position;
private bool _reserve;
public string nom
{
get { return _nom; }
set { _nom = value; }
}
public string prenom
{
get { return _prenom; }
set { _prenom = value; }
}
public DateTime dateDeNaissance
{
get { return _dateDeNaissance; }
set { _dateDeNaissance = value; }
}
public string position
{
get { return _position; }
set { _position = value; }
}
public bool reserve
{
get { return _reserve; }
set { _reserve = value; }
}
public Joueur()
{
}
public Joueur(string nom, string prenom, DateTime dateDeNaissance, string position, bool reserve)
{
this.nom = nom;
this.prenom = prenom;
this.dateDeNaissance = dateDeNaissance;
this.position = position;
this.reserve = reserve;
}
public double virtual CalculerPrime(int joues, int gagnes)
{
double Prime;
if (reserve == false)
Prime = 10000 * (gagnes / joues);
else
Prime = ((10000 * (gagnes / joues)) / 2);
return Prime;
}
}
You need to do like this in your code:
public virtual double CalculerPrime(int joues, int gagnes)
{
double Prime;
if (reserve == false)
Prime = 10000 * (gagnes / joues);
else
Prime = ((10000 * (gagnes / joues)) / 2);
return Prime;
}
Related
I have this functional query where I only used fictive tables names for security concerns :
SELECT
h.CENID,
h.BMHFMC,
h.BMHDONEMIDASSTEP1,
h.BMHDONEMIDASSTEP2,
h.LMIID,
h.BMHHOLD,
h.BMHBATCHMIDAS,
h.BMHFMCVALUEDATE AS HeaderValueDate,
h.SUNID,
h.BRAID,
d.BMHID,
d.BMDRUBRIQUE,
d.BMDCLIENT,
d.BMDSEQUENCE,
d.BMDDATE,
d.BMDDEVISE,
d.BMDMONTANT,
d.BMDTYPE,
d.BMDNOTE,
d.BMDENTRYNBRE,
v.DEVDECIMAL ,
NVL(t.TYPVERIFCOMPTEMIDAS, 0) AS TYPVERIFCOMPTEMIDAS
FROM dbo.TableOne h
INNER JOIN dbo.Tabletwoo d
ON h.BMHID = d.BMHID
INNER JOIN dbo.tableThree v
ON d.BMDDEVISE = v.DEVID
LEFT JOIN dbo.TableFour t
ON t.TYPID=h.BMHFMC
WHERE d.BMDMONTANT != 0
AND h.BMHDONEMIDASSTEP1 = 0
AND h.BMHDONEMIDASSTEP2 = 0
AND h.LMIID = 0
AND h.BMHHOLD = 0
And I made a class in order to bind every fields
public class Batch :BaseRepository ,IList<Batch>
{
public Batch()
{
}
private string cendid;
private string bmhfmc;
private double bmhdonemidasstep1;
private double bmhdonemidasstep2;
private double lmiid;
private double bmhhold;
private double bmhbatchmidas;
private DateTime headervaluedateordinal;
private double sunid; //
private string bradid; //
private double bmhid;
private string bmdrubirique; //
private string bmdclient;
private string bmdsequence;
private DateTime bmddate;
private string bmddevise;
private double bmdmontant;
private string bmdtype;
private string bmdnote;
private string bmdentrynbre; //
private double devdecimalordinal;
private double typverifcomptemidasordinal;
public Batch(string cendid, string bmhfmc, double bmhdonemidasstep1, double bmhdonemidasstep2, double lmiid, double bmhhold, double bmhbatchmidas, DateTime headervaluedateordinal, double sunid, string bradid, double bmhid, string bmdrubirique, string bmdclient, string bmdsequence, DateTime bmddate, string bmddevise, double bmdmontant, string bmdtype, string bmdnote, string bmdentrynbre, double devdecimalordinal, double typverifcomptemidasordinal)
{
this.cendid = cendid;
this.bmhfmc = bmhfmc;
this.bmhdonemidasstep1 = bmhdonemidasstep1;
this.bmhdonemidasstep2 = bmhdonemidasstep2;
this.lmiid = lmiid;
this.bmhhold = bmhhold;
this.bmhbatchmidas = bmhbatchmidas;
this.headervaluedateordinal = headervaluedateordinal;
this.sunid = sunid;
this.bradid = bradid;
this.bmhid = bmhid;
this.bmdrubirique = bmdrubirique;
this.bmdclient = bmdclient;
this.bmdsequence = bmdsequence;
this.bmddate = bmddate;
this.bmddevise = bmddevise;
this.bmdmontant = bmdmontant;
this.bmdtype = bmdtype;
this.bmdnote = bmdnote;
this.bmdentrynbre = bmdentrynbre;
this.devdecimalordinal = devdecimalordinal;
this.typverifcomptemidasordinal = typverifcomptemidasordinal;
}
public string Cendid
{
get { return cendid; }
set { cendid = value; }
}
public string Bmhfmc
{
get { return bmhfmc; }
set { bmhfmc = value; }
}
public double Bmhdonemidasstep1
{
get { return bmhdonemidasstep1; }
set { bmhdonemidasstep1 = value; }
}
public double Bmhdonemidasstep2
{
get { return bmhdonemidasstep2; }
set { bmhdonemidasstep2 = value; }
}
public double Lmiid
{
get { return lmiid; }
set { lmiid = value; }
}
public double Bmhhold
{
get { return bmhhold; }
set { bmhhold = value; }
}
public double Bmhbatchmidas
{
get { return bmhbatchmidas; }
set { bmhbatchmidas = value; }
}
public DateTime Headervaluedateordinal
{
get { return headervaluedateordinal; }
set { headervaluedateordinal = value; }
}
public double Sunid
{
get { return sunid; }
set { sunid = value; }
}
public string Bradid
{
get { return bradid; }
set { bradid = value; }
}
public double Bmhid
{
get { return bmhid; }
set { bmhid = value; }
}
public string Bmdrubirique
{
get { return bmdrubirique; }
set { bmdrubirique = value; }
}
public string Bmdclient
{
get { return bmdclient; }
set { bmdclient = value; }
}
public string Bmdsequence
{
get { return bmdsequence; }
set { bmdsequence = value; }
}
public DateTime Bmddate
{
get { return bmddate; }
set { bmddate = value; }
}
public string Bmddevise
{
get { return bmddevise; }
set { bmddevise = value; }
}
public double Bmdmontant
{
get { return bmdmontant; }
set { bmdmontant = value; }
}
public string Bmdtype
{
get { return bmdtype; }
set { bmdtype = value; }
}
public string Bmdnote
{
get { return bmdnote; }
set { bmdnote = value; }
}
public string Bmdentrynbre
{
get { return bmdentrynbre; }
set { bmdentrynbre = value; }
}
public double Devdecimalordinal
{
get { return devdecimalordinal; }
set { devdecimalordinal = value; }
}
public double Typverifcomptemidasordinal
{
get { return typverifcomptemidasordinal; }
set { typverifcomptemidasordinal = value; }
}
Now when I execute the query into a list using dapper
Connection conn = new Connection();
OracleConnection connection = conn.GetDBConnection();
myList= connection.Query<Batch>(querySql).ToList();
Now,while debugging, all fields returns the expected values .But, I noticed those fields below are null in myList not empty but really null , but the problem is they aren't null in the database
Bmdrubirique , Sunid, Bmdentrynbre, Bradid ,Cenid
In oracle database those fields are like the following :
CENID is VARCHAR2(3 BYTE)`
Bmhid is VARCHAR2(3 BYTE)
Sunid is NUMBER(38,0)
Bradid is VARCHAR2(3 BYTE)
I don't get it , where did it go wrong? why other fields are properly loaded while those returns null value ?
My default assumption would be that there is a typo in the real code and the constructor is assigning a value from a field to itself. However, frankly: since you have a public Batch() {} constructor, I'm not sure what the benefit of the second one is - it just adds risk of errors. Likewise with the fields and manual properties.
So if this as me, where you currently have (simplified to two properties):
public class Batch
{
private string cendid;
private string bmhfmc;
public Batch() {}
public Batch(string cendid, string bmhfmc)
{
this.cendid = cendid;
this.bmhfmc = bmhfmc;
}
public string Cendid
{
get { return cendid; }
set { cendid = value; }
}
public string Bmhfmc
{
get { return bmhfmc; }
set { bmhfmc = value; }
}
}
I would have literally just:
public class Batch
{
public string Cendid {get;set;}
public string Bmhfmc {get;set;}
}
All of the rest of the code is just opportunities to make coding errors.
Now: the reason that Cendid is null is because: the column is CENID - only one d. This means that dapper isn't even using your custom constructor, because it isn't a perfect match between the constructor and the columns. Ditto the other fields like BRAID vs BRADID.
So the next thing to do is to fix the typos.
I am a little lost here.
Basically, I need to access an array item, a string and display it. Here is the code.
namespace Test3_2_Practice
{
public partial class InterfaceImplementation : Form
{
//Array
ICombatant[] combatants = new ICombatant[2];
public InterfaceImplementation()
{
InitializeComponent();
}
private void btnTest_Click(object sender, EventArgs e)
{
combatants[0] = new PlayerCharacter ("Conan" , 500);
combatants[1] = new MonsterCharacter ("Bob" , 5);
combatants[2] = new MonsterCharacter ("Snake" , 15);
string output = "Fighters" + Environment.NewLine;
for (var i = 0; i < combatants.Length; i++)
{
var character = combatants[i];
output += "Character:" + combatants[i].
}
}
}
}
So I have my array, combatants composed of two types of instances. I want to access the name, "Conan" and add it to a string for output. How do I go about doing that? Here is the rest of the code if that helps. Thanks!
namespace Test3_2_Practice
{
//Interface
interface ICombatant
{
int TakeDamage(int damageAmount);
string GetHealthDisplay();
}
class PlayerCharacter : ICombatant
{
private string characterName;
private int currentHealth;
private int maxHealth;
public string CharacterName
{
get { return characterName; }
set { characterName = value; }
}
public int CurrentHealth
{
get { return currentHealth; }
set { currentHealth = value; }
}
public int MaxHealth
{
get { return maxHealth; }
set { maxHealth = value; }
}
public PlayerCharacter(string characterName, int maxHealth)
{
CharacterName = characterName;
CurrentHealth = MaxHealth = maxHealth;
}
//Damage Class
public int TakeDamage(int damageAmount)
{
if (damageAmount > currentHealth)
{
damageAmount = currentHealth;
return damageAmount;
}
else
{
currentHealth = currentHealth - damageAmount;
return damageAmount;
}
}
//Health Class
public string GetHealthDisplay()
{
return ("Health " + CurrentHealth.ToString() + "/" + MaxHealth).ToString();
}
}
class MonsterCharacter : ICombatant
{
private string monsterName;
private int health;
public string MonsterName
{
get { return monsterName; }
set { monsterName = value; }
}
public int Health
{
get { return health; }
set { health = value; }
}
public MonsterCharacter(string monsterName, int health)
{
MonsterName = monsterName;
Health = health;
}
//Damage Class
public int TakeDamage(int damageAmount)
{
if(damageAmount > health)
{
damageAmount = health;
return damageAmount;
}
else
{
health = health - damageAmount;
return damageAmount;
}
}
//Health Class
public string GetHealthDisplay()
{
return "Health " + Health;
}
}
}
Actually, since name is common to all implementer of interface that Name property should be included to interface itself like
interface ICombatant
{
int TakeDamage(int damageAmount);
string GetHealthDisplay();
public string CharacterName
{
get;
set;
}
}
In your current scenario, you will have to cast it specific concrete type before accessing it
var character = combatants[i];
if(character is PlayerCharacter)
output += "Character:" + ((PlayerCharacter)character).CharacterName;
It's better to make a good use of your interface. Create a new method in your interface:
interface ICombatant
{
int TakeDamage(int damageAmount);
string GetHealthDisplay();
string GetCombatantName(); // added this
}
Then implement in both classes which implements it:
class PlayerCharacter : ICombatant
{
// ... a lot of code ...
public string GetCombatantName()
{
return String.Format("Character: {0}", this.CharacterName);
}
}
class MonsterCharacter: ICombatant
{
// ... a lot of code ...
public string GetCombatantName()
{
return String.Format("Monster: {0}", this.MonsterName);
}
}
And use it like this:
private void btnTest_Click(object sender, EventArgs e)
{
combatants[0] = new PlayerCharacter("Conan", 500);
combatants[1] = new MonsterCharacter("Bob", 5);
combatants[2] = new MonsterCharacter("Snake", 15);
string output = "Fighters" + Environment.NewLine;
foreach (var combatant in combatants)
{
output += combatant.GetCombatantName();
}
}
So if one day you get ten distinct types of ICombatant (like AnimalCharacter, VirusCharacter), you don't have to nest a lot of ifs to check and cast types to get the proper property.
Interfaces are meant exactly to avoid this kind of stuff, hiding the implementation details.
I am currently working on a BMI calculator for my C# class. My app asks the user for either their height in feet and inches and their weight in pounds or their height in centimeters and weight in kilograms. Their is a tab control that has buttons for Imperial mode or Metric mode.
If the "calculate" button in the imperial tab is clicked, I need to make sure that the heightFt, heightIn, and weightLbs text boxes have been filled out. Then I convert those to the metric units. If the calculate button in the metric tab is clicked, I need to make sure that the heightCm and weightKg text boxes have been filled out.
Once those are provided, I then convert the height and weight to BMI. If I use if(heightFt == null) I get the following error:
The result of the expression is always 'false' since a value of type 'double' is never equal to 'null' of type 'double?'
How do I fix this?
This is my MainWindow.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace BMICalculator
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private BMICalc _BMICalc;
public MainWindow()
{
_BMICalc = new BMICalc();
InitializeComponent();
}
private void calculateImperial_Click(object sender, RoutedEventArgs e)
{
_BMICalc.heightFt = Convert.ToDouble(heightFt.Text);
_BMICalc.heightIn = Convert.ToDouble(heightIn.Text);
_BMICalc.weightLbs = Convert.ToDouble(weightLbs.Text);
_BMICalc.doCalculation("Imperial");
if (_BMICalc.error == null)
{
MessageBox.Show("Your BMI is " + _BMICalc.bmi + " and you are " + _BMICalc.category, "Your BMI");
}
}
}
}
This is BMICalc.cs
using System;
using System.Windows;
using System.ComponentModel;
namespace BMICalculator
{
class BMICalc :INotifyPropertyChanged
{
public double _heightFt { get; set; }
public double _heightIn { get; set; }
public double _heightCm { get; set; }
public double _weightLbs { get; set; }
public double _weightKg { get; set; }
public double _bmi { get; set; }
public string _category { get; set; }
public string _error { get; set; }
public double heightFt
{
get { return heightFt; }
set
{
_heightFt = value;
OnPropertyChanged("heightFt");
}
}
public double heightIn
{
get { return _heightIn; }
set
{
_heightIn = value;
OnPropertyChanged("heightIn");
}
}
public double heightCm
{
get { return _heightCm; }
set
{
_heightCm = value;
OnPropertyChanged("heightCm");
}
}
public double weightLbs
{
get { return _weightLbs; }
set
{
_weightLbs = value;
OnPropertyChanged("weightLbs");
}
}
public double weightKg
{
get { return _weightKg; }
set
{
_weightKg = value;
OnPropertyChanged("weightKg");
}
}
public double bmi
{
get { return _bmi; }
set
{
_bmi = value;
OnPropertyChanged("bmi");
}
}
public string error
{
get { return _error; }
set
{
_error = value;
OnPropertyChanged("error");
}
}
public string category
{
get { return _category; }
set
{
_category = value;
OnPropertyChanged("category");
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyName){
if(PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
public void doCalculation(string calculationMode){
if(calculationMode == "Imperial"){
if (heightFt == null)
{
this.error = "You must provide a value for your height in feet!";
}
else if (heightIn == null)
{
this.error = "You must provide a value for your height in inches!";
}
else if (weightLbs == null)
{
this.error = "You must provide a value for your weight in pounds!";
}
else
{
heightFt = Convert.ToDouble(heightFt);
heightIn = Convert.ToDouble(heightIn);
weightLbs = Convert.ToDouble(weightLbs);
_weightKg = Convert.ToDouble(_weightLbs * (1 / 2.2));
_heightCm = Convert.ToDouble((_heightFt + (_heightIn / 12) / 0.032808));
}
} else if(calculationMode == "Metric"){
this.bmi = weightKg / Math.Pow((heightCm / 100), 2);
if (this.bmi < 18.5)
{
this.category = "underweight";
}
else if (this.bmi >= 18.5 && this.bmi < 24.9)
{
this.category = "normalweight";
}
else if (this.bmi >= 25 && this.bmi <= 29.9)
{
this.category = "overweight";
}
else if (this.bmi > 30)
{
this.category = "obese";
}
}
}
}
}
}
You can make you double properties to be nullable so you can compare to null (the default).
Example:
public double? heightIn
{
get { return _heightIn; }
set {
_heightIn = value;
OnPropertyChanged("heightIn");
}
}
In this case, make sure you change the type of the corresponding private variables to match.
You never set a default value for your properties. As double cannot be null you'll probably want to check against 0 instead. The properties you begin with underscores should just be private variables with default values. Also consider using metric only internally.
class BMICalc :INotifyPropertyChanged
{
private double _heightFt = 0;
private double _heightIn = 0;
private double _heightCm = 0;
private double _weightLbs = 0;
private double _weightKg = 0;
private double _bmi = 0;
private string _category = null;
private string _error = null;
public double heightFt
{
get { return _heightFt; }
set
{
_heightFt = value;
OnPropertyChanged("heightFt");
}
}
public double heightIn
{
get { return _heightIn; }
set
{
_heightIn = value;
OnPropertyChanged("heightIn");
}
}
public double heightCm
{
get { return _heightCm; }
set
{
_heightCm = value;
OnPropertyChanged("heightCm");
}
}
public double weightLbs
{
get { return _weightLbs; }
set
{
_weightLbs = value;
OnPropertyChanged("weightLbs");
}
}
public double weightKg
{
get { return _weightKg; }
set
{
_weightKg = value;
OnPropertyChanged("weightKg");
}
}
public double bmi
{
get { return _bmi; }
set
{
_bmi = value;
OnPropertyChanged("bmi");
}
}
public string error
{
get { return _error; }
set
{
_error = value;
OnPropertyChanged("error");
}
}
public string category
{
get { return _category; }
set
{
_category = value;
OnPropertyChanged("category");
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyName){
if(PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
public void doCalculation(string calculationMode){
if(calculationMode == "Imperial"){
if (heightFt == null)
{
this.error = "You must provide a value for your height in feet!";
}
else if (heightIn == null)
{
this.error = "You must provide a value for your height in inches!";
}
else if (weightLbs == null)
{
this.error = "You must provide a value for your weight in pounds!";
}
else
{
heightFt = Convert.ToDouble(heightFt);
heightIn = Convert.ToDouble(heightIn);
weightLbs = Convert.ToDouble(weightLbs);
_weightKg = Convert.ToDouble(_weightLbs * (1 / 2.2));
_heightCm = Convert.ToDouble((_heightFt + (_heightIn / 12) / 0.032808));
}
} else if(calculationMode == "Metric"){
this.bmi = weightKg / Math.Pow((heightCm / 100), 2);
if (this.bmi < 18.5)
{
this.category = "underweight";
}
else if (this.bmi >= 18.5 && this.bmi < 24.9)
{
this.category = "normalweight";
}
else if (this.bmi >= 25 && this.bmi <= 29.9)
{
this.category = "overweight";
}
else if (this.bmi > 30)
{
this.category = "obese";
}
}
}
}
}
IDE: Microsoft Visual Studio 2010
Language : C#, XML
I am trying to deserialize XML file to object, but it throws me the error in XML document (5,4).Any suggestions ?
Here is the code I have tried ...
public void ReadXMLtblFieldingDetails(string xmlFileXDetails)
{
XmlSerializer serializer = new XmlSerializer(typeof(tblXDetails));
TextReader reader = new StreamReader(xmlXDetails);
object obj = serializer.Deserialize(reader);
tblXDetails XmlData = (tblXDetails)obj;
BusinessObjectManager.Add(XmlData);
}
And this is the XML document I want to deserialize ...
<?xml version="1.0"?>
<tblXDetails xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<RowModified>0001-01-01T00:00:00</RowModified>
<MachineID>6A7FEBFDCEFC4DSSDAXX</MachineID>
<fielder1_x_axis>0</fielder1_x_axis>
<fielder1_y_axis>0</fielder1_y_axis>
<fielder2_x_axis>0</fielder2_x_axis>
<fielder2_y_axis>0</fielder2_y_axis>
<fielder3_x_axis>0</fielder3_x_axis>
<fielder3_y_axis>0</fielder3_y_axis>
<fielder4_x_axis>0</fielder4_x_axis>
<fielder4_y_axis>0</fielder4_y_axis>
<fielder5_x_axis>0</fielder5_x_axis>
<fielder5_y_axis>0</fielder5_y_axis>
<fielder6_x_axis>0</fielder6_x_axis>
<fielder6_y_axis>0</fielder6_y_axis>
<fielder7_x_axis>0</fielder7_x_axis>
<fielder7_y_axis>0</fielder7_y_axis>
<fielder8_x_axis>0</fielder8_x_axis>
<fielder8_y_axis>0</fielder8_y_axis>
<fielder9_x_axis>0</fielder9_x_axis>
<fielder9_y_axis>0</fielder9_y_axis>
</tblxDetails>
Here is the error : Error in XML Document(5,4) //Invalid Operation Exception was unhandled by user code
tblXDetails class:
public class tblXDetails
{
decimal _MachineID;
float _fielder1_x_axis;
float _fielder1_y_axis;
float _fielder2_x_axis;
float _fielder2_y_axis;
float _fielder3_x_axis;
float _fielder3_y_axis;
float _fielder4_x_axis;
float _fielder4_y_axis;
float _fielder5_x_axis;
float _fielder5_y_axis;
float _fielder6_x_axis;
float _fielder6_y_axis;
float _fielder7_x_axis;
float _fielder7_y_axis;
float _fielder8_x_axis;
float _fielder8_y_axis;
float _fielder9_x_axis;
float _fielder9_y_axis;
public decimal MachineID
{
get { return _MachineID; }
set { _MachineID = value; }
}
public float fielder1_x_axis
{
get { return _fielder1_x_axis; }
set { _fielder1_x_axis = value; }
}
public float fielder1_y_axis
{
get { return _fielder1_y_axis; }
set { _fielder1_y_axis = value; }
}
public float fielder2_x_axis
{
get { return _fielder2_x_axis; }
set { _fielder2_x_axis = value; }
}
public float fielder2_y_axis
{
get { return _fielder2_y_axis; }
set { _fielder2_y_axis = value; }
}
public float fielder3_x_axis
{
get { return _fielder3_x_axis; }
set { _fielder3_x_axis = value; }
}
public float fielder3_y_axis
{
get { return _fielder3_y_axis; }
set { _fielder3_y_axis = value; }
}
public float fielder4_x_axis
{
get { return _fielder4_x_axis; }
set { _fielder4_x_axis = value; }
}
public float fielder4_y_axis
{
get { return _fielder4_y_axis; }
set { _fielder4_y_axis = value; }
}
public float fielder5_x_axis
{
get { return _fielder5_x_axis; }
set { _fielder5_x_axis = value; }
}
public float fielder5_y_axis
{
get { return _fielder5_y_axis; }
set { _fielder5_y_axis = value; }
}
public float fielder6_x_axis
{
get { return _fielder6_x_axis; }
set { _fielder6_x_axis = value; }
}
public float fielder6_y_axis
{
get { return _fielder6_y_axis; }
set { _fielder6_y_axis = value; }
}
public float fielder7_x_axis
{
get { return _fielder7_x_axis; }
set { _fielder7_x_axis = value; }
}
public float fielder7_y_axis
{
get { return _fielder7_y_axis; }
set { _fielder7_y_axis = value; }
}
public float fielder8_x_axis
{
get { return _fielder8_x_axis; }
set { _fielder8_x_axis = value; }
}
public float fielder8_y_axis
{
get { return _fielder8_y_axis; }
set { _fielder8_y_axis = value; }
}
public float fielder9_x_axis
{
get { return _fielder9_x_axis; }
set { _fielder9_x_axis = value; }
}
public float fielder9_y_axis
{
get { return _fielder9_y_axis; }
set { _fielder9_y_axis = value; }
}
The MachineID must be a decimal (according to your class definition) but in the xml an incompatible value is provided: 6A7FEBFDCEFC4DSSDAXX. If you set it to 1 in the xml the serialization passes. I'm afraid you'll need to write a custom (de)serializer or change the type of the MachineID if possible.
I'm having a small issue calling in the Icloneable interface
I've told the class I want to use the interface as such:
class UnitClass: ICloneable
and have placed in a function for Cloning
public Object Clone()
{
return this.MemberwiseClone();
}
however for some reason the program is telling me that I have not implemented System.ICloneable.clone() I even tried giving the function the explicit name like so...
public Object System.ICloneable.Clone()
but with little effect, anybody know what I'm doing wrong?
edit: Full class
class UnitClass: ICloneable
{
//-----------------------------------------------------------------------------------------------
//----------------------------------------------Variables----------------------------------------
private int unitID; //added for xml
private string unitName;
private int unitBaseHP;
private int unitCurrentHP;
private Carrier unitCarrier;
private int unitRechargeTime;
private int turnLastPlayed;
private int strengthAgainstFighters;
private int strengthAgainstBombers;
private int strengthAgainstTurrets;
private int strengthAgainstCarriers;
//-----------------------------------------------------------------------------------------------
//---------------------------------------------Constructor---------------------------------------
public UnitClass()
{
unitID = 0;
unitName = "Name Not Set";
unitBaseHP = 0;
unitCurrentHP = 0;
unitCarrier = null;//Carrier works as faction ie red/blue or left/right
unitRechargeTime = 0;
turnLastPlayed = 0;
strengthAgainstFighters = 0;
strengthAgainstBombers = 0;
strengthAgainstTurrets = 0;
strengthAgainstCarriers = 0;
}
//-----------------------------------------------------------------------------------------------
//---------------------------------------------Gets and Sets-------------------------------------
public int UnitID//public
{
set { unitID = value; }
get { return unitID; }
}
public string UnitName//public
{
set { unitName = value; }
get { return unitName; }
}
public int UnitBaseHP//public
{
set { unitBaseHP = value; }
get { return unitBaseHP; }
}
public int UnitCurrentHP//public
{
set { unitCurrentHP = value; }
get { return unitCurrentHP; }
}
public Carrier UnitCarrier//public
{
set { unitCarrier = value; }
get { return unitCarrier; }
}
public int UnitRechargeTime//public
{
set { unitRechargeTime = value; }
get { return unitRechargeTime; }
}
public int TurnLastPlayed//public
{
set { turnLastPlayed = value; }
get { return turnLastPlayed; }
}
public int StrengthAgainstFighters//public
{
set { strengthAgainstFighters = value; }
get { return strengthAgainstFighters; }
}
public int StrengthAgainstBombers//public
{
set { strengthAgainstBombers = value; }
get { return strengthAgainstBombers; }
}
public int StrengthAgainstTurrets//public
{
set { strengthAgainstTurrets = value; }
get { return strengthAgainstTurrets; }
}
public int StrengthAgainstCarriers//public
{
set { strengthAgainstCarriers = value; }
get { return strengthAgainstCarriers; }
}
//---------------------------------------------------------------------------
public object Clone()
{
return this.MemberwiseClone();
}
}
This built fine for me.
public class MyClone : ICloneable
{
public object Clone()
{
return this.MemberwiseClone();
}
}
You don't perhaps want to share any more of your class? Nothing is really jumping out at me.