|
Wait a minute, aren't you creating a class and not a variable?
|
|
|
|
|
Sure, that example - you can create a private class inside another class. Or use 3 private variables or use a struct.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
He seems below to be saying he wants to store a string that contains the name and the balance. He actually had the code to do that posted.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
I think you need to talk to your teacher. It sounds like you're struggling with some real basics.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
This might just be poor wording on part of the writer, but what does this mean:
"Each object of the class contains a private instance variable savingsBalance, indicating the amount the saver has on deposit along with the account holder's first and last names."
Is the private instance variable this:
static private object savingsBalance = firstName + " " + lastName + "has $" + amount;
And what does "each object of the class" mean? Isn't every single keyword an object?
Edit:
He wants me to calculate stuff with savingsBalance but I do not think I am able to do that with an object that includes a string with a word like "has"
modified on Sunday, August 2, 2009 5:44 PM
|
|
|
|
|
I think he means "each instance of the class". But that's just a guess.
And the fact that he said it was a private instance variable means it is NOT a static .
|
|
|
|
|
Nathan Revka wrote: He wants me to calculate stuff with savingsBalance but I do not think I am able to do that with an object that includes a string
This makes your teacher a bit dumb, IMO, but you can convert a string into a number using decimal.TryParse, or int.TryParse, depending on what type you want. You can also use the decimal.Parse or even Convert.ToInt32, etc, but the tryparse will not blow up if the string does not contain a number.
Of course, if amount is a number, then that's all you would use to calculate with. Storing the savingsBalance as a string, seems odd to me, the balance is the number, the rest is the account name. The string might be rendered by a helper method, but surely amount is also being stored somewhere ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
hello everybody,
i'm going to begin a project that need the following :
Requirement Analysis & Definition --> 5 days
System & Software Design --> 18 days
Implementation & Unit Testing --> 77 days
Integration & System Testing --> undetermined
Operations & Maintenance --> undetermined
could anybody advice or give me an estimation or hint how much should i ask as for a logical price.
thank you so much for your usual coordination
|
|
|
|
|
michael_jhons wrote: could anybody advice or give me an estimation or hint how much should i ask as for a logical price.
This is no C# question.
There is Sales/Marketing [^]forum in CP.
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
Hello again. I've painted myself into a corner once more - this time with a different colour of paint!
I am trying to understand how to use XmlAttributeOverrides() to control the deserialisation of an XML file, but I can't seem to figure out how to tell it what I want to do. I have created a running example.
Using this XML:
<?xml version="1.0" encoding="utf-8"?>
<orchestra>
<bloweythingy name="flute" reed="false"/>
<bloweythingy name="oboe" reed="true"/>
<hitythingy name="tympani" keys="false"/>
<hitythingy name="piano" keys="true"/>
</orchestra>
I would like to create an Orchestra object that contains 2 objects of class Woodwind (representing the contents of the bloweything elements) and 2 of class Percussion (representing hitythingy content). Both Woodwind and Percussion are derived from class Instrument .
Additionally, I would like to do this without decorating the classes with [XmlElement] attributes so that, later on, I will be able to programatically add new Instrument types. To do this, I created a "registry" to which the code will be able to add an XML tag name and the class to be used to represent the data in that tag. Eventually, the registry will cache the XmlSerializer objects to be used with each tag... but for now the serialisers are created on the fly.
Here is the code to try and do this:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
namespace Deserialising
{
class ExampleA
{
static void Main(string[] args)
{
XmlSerializer iniSerializer = new XmlSerializer(typeof(Orchestra));
TextReader iniReader = new StreamReader("C:\\Temp\\ExampleOrchestra.xml");
try
{
Orchestra DuchyOfGrandFenwickPhilharmonic = (Orchestra)iniSerializer.Deserialize(iniReader);
}
catch (Exception ex)
{
while (ex != null)
{
Console.WriteLine(ex.Message);
ex = ex.InnerException;
}
Console.ReadKey();
}
iniReader.Close();
}
}
[XmlRoot("orchestra")]
public class Orchestra : IXmlSerializable
{
private Dictionary<string, Type> RegisteredElements;
private XmlAttributeOverrides instrumentXmlOverrides;
public Orchestra()
{
this.RegisteredElements = new Dictionary<string, Type>();
this.Compliment = new List<Instrument>();
RegisteredElements.Add("bloweythingy", typeof(Woodwind));
RegisteredElements.Add("hitythingy", typeof(Percussion));
instrumentXmlOverrides = new XmlAttributeOverrides();
foreach (KeyValuePair<string, Type> kvp in RegisteredElements)
{
XmlElementAttribute xea = new XmlElementAttribute(kvp.Key, kvp.Value);
XmlAttributes xa = new XmlAttributes();
xa.XmlElements.Add(xea);
instrumentXmlOverrides.Add(typeof(Instrument), kvp.Value.Name, xa);
}
}
public List<Instrument> Compliment { get; set; }
#region IXmlSerializable methods
public XmlSchema GetSchema() { return null; }
public void ReadXml(XmlReader reader)
{
reader.ReadStartElement();
while (reader.NodeType != XmlNodeType.EndElement)
{
XmlSerializer ts = new XmlSerializer(typeof(Instrument), instrumentXmlOverrides);
this.Compliment.Add((Instrument)(ts.Deserialize(reader)));
}
reader.ReadEndElement();
}
public void WriteXml(XmlWriter writer) { }
#endregion
}
public class Instrument
{
[XmlAttribute("name")]
public string Name { get; set; }
}
public class Woodwind : Instrument
{
[XmlAttribute("reed")]
public bool hasReed { get; set; }
}
public class Percussion : Instrument
{
[XmlAttribute("keys")]
public bool hasKeys { get; set; }
}
}
I have tried all combinations of variations A, B and C with subvariations 1 and 2... but to no avail. I keep being told that bloweything is not expected or that the root element is missing. The combination that is uncommented above (A and 1) is the one that I (IMHO) think should work. The following annotations are intended to show what I thought the code would do:
<small>when kvp = {"bloweything", typeof(Woodwind)}:</small>
XmlElementAttribute xea = new XmlElementAttribute(kvp.Key, kvp.Value);
<small>= associate <bloweything> tags with Woodwind classes</small>
XmlAttributes xa = new XmlAttributes();
xa.XmlElements.Add(xea);
<small>= we now have a new rule: <bloweythingy> becomes Woodwind (deserialising) and Woodwinds are written as <bloweythingy> (serialising)</small>
instrumentXmlOverrides.Add(typeof(Instrument), kvp.Value.Name, xa);
<small>= when told to deserialise an Instrument [parm 1], if you run across a <bloweythingy> tag [parm2] apply the rules in xa (deserialise the <bloweythingy> tags into Woodwinds) [parm 3]</small>
...
<small>when reader.Name = "bloweythingy":</small>
XmlSerializer ts = new XmlSerializer(typeof(Instrument), instrumentXmlOverrides);
<small>= I'm telling you to deserialise an Instrument using the above stated rules, so you should turn the <bloweythingy> into a Woodwind</small>
this.Compliment.Add((Instrument)(ts.Deserialize(reader)));
<small>= @#$%# - WHY WON'T .NET LISTEN TO ME?!?!? I HATE COMPUTERS</small>
Any help would be appreciated. Thanks.
Clive Pottinger
Victoria, BC
|
|
|
|
|
cpotting wrote: XmlSerializer iniSerializer = new XmlSerializer(typeof(Orchestra));
It looks like you are using a wrong overload of XmlSerializer constructor. I can't see anywhere in your code where XmlSerializer is getting your XmlAttributeOverrides object. Try with this[^] overload instead.
|
|
|
|
|
Thanks Navaneeth.
To answer point about where the XmlSerializer was getting my XmlAttributesOverrides object: the idea was to have the Orchestra class deserialise each <bloweythingy> and <hittythingy> tag as it encountered them. To do this Orchestra implement IXmlSerializable and the deserialisation was done inside the ReadXml() method. So the XmlAttributeOverrides were being assigned to the XmlSerializer ts in the Orchestra class, not the iniSerializer in Main .
That was the idea.
But after carefully examining the example you linked to, I now realise my mistake: I misunderstood the meaning of each parameter in the XmlAttributeOverrides.Add() method. I had written
instrumentXmlOverrides.Add(typeof(Instrument), kvp.Value.Name, xa);
<small>= when told to deserialise an Instrument [parm 1], if you run across a <bloweythingy> tag [parm2] apply the rules in xa (deserialise the <bloweythingy> tags into Woodwinds) [parm 3]</small> I thought the first 2 parms were the class being deserialised and the "alternate" tagname for that class (Instrument and <bloweythingy> ). In reality they are the class being deserialised and the tagname/class name of a property of that class. I should have been trying do this:
instrumentXmlOverrides.Add(typeof(Orchestra), "Instrument", xa);
<small>= when told to deserialise an Orchestra [parm 1], where you would normally expect an Instrument tag [parm2] apply the rules in xa (which should include both alternate tagnames for Instrument [bloweythingy and hittythingy] and their classes [Woodwinds and Percussion]) [parm 3]</small>
In order to do that, I had to reorganise my code so that the overrides were all constructed before ever trying to deserialise Orchestra . That allowed me to remove the IXmlSerializable interface from Orchestra and simplify the code.
Thanks again, Navaneeth. I can now move ahead with the actual application I am writing.
Clive Pottinger
Victoria, BC
|
|
|
|
|
Great. Happy to help
|
|
|
|
|
Yeah, and you've misspelled hittythingy , as well!!
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Henry Minute wrote: Yeah, and you've misspelled hittythingy, as well!! Big Grin
I checked AskOford.com first - but appearently, it is not a term in common usage in England. So I was left to guess.
I have corrected my code
Clive Pottinger
Victoria, BC
|
|
|
|
|
Trying to provide a backup "button" inside the C# Windows Forms application on a client PC that connects to a SQL Server database, I want to grab the resulting backup file of a call to the BACKUP DATABASE[^] T-SQL function.
Since the BACKUP DATABASE function takes a file path that is relative to the SQL Server itself, I see no reliable way to get the resulting backup file from the client.
My ideal way would be:
1.) Call the BACKUP DATABASE function from my client application.
2.) Specify to backup to a local file (or even better: a C#/.NET stream[^]).
3.) Capture the resulting BAK file from my client application.
Question: Is this possible to achieve?
(I will cross-post this message to the Database forum, since I am unsure whether this is more an ADO.NET topic)
Thanks
Uwe
|
|
|
|
|
Few ideas,
1 - Install FTP on the database server. Configure the directory where SQL server writes backup files to be accessed through FTP. Once the backup is done, your client application can look into this FTP space and download the backup file.
2 - Change the SQL server back up directory by changing registry entries explained in this[^] article.
|
|
|
|
|
Thanks for your ideas!
I try whether this fits my needs.
Best regards
Uwe
|
|
|
|
|
Can't you set the backup folder to be a fileshare, detect when the backup is completed and grab it from there.
I am pretty sure you cannot backup to a stream object .
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Thanks for your answer!
Seems an interesting idea to further follow.
The idea was to have the user do ZERO configuration, except specifying the connection string. Hopefully I will manage to do.
Cheers
Uwe
|
|
|
|
|
i have one form in the application.it runs in start up and i want to display the icon the tray. and when i click the icon the form shud be displayed
how can i do this..........
there is only one form
can any one help me.....
This code was posted by me...
|
|
|
|
|
There is this [^]article in CP about this.
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
This was my first Article at CP
|
|
|
|
|
And still usefull
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
First drag a ContextMenuStrip from the tool box...................... then just create one label on it and write just the text you want to be displayed ........................ like 'Open Form1'................... then double click it and write like ..... "Form1.show".................... on the property of your notifyIcon change the value of ContextMenuStirp from none to ContextMenuStrip1 ............................ I think this must work....
good luck
|
|
|
|