|
So, is it? I heard C# is the evolution of C++ somewhere. I cant seem to find my answer anywhere. Thanks for the help, I'm new to these forums and coding.
|
|
|
|
|
Not really. Bjarne Stroustrup, the creator of the C++ language, recently said that C++ is the the grandparent of C#, in that Java is the parent of C#, and Java's parent is C++.
Java evolved from C++ in that it is a simpler, less powerful but less complex version of C++. C# is closer to C++ than Java, ironically, due to its ability to use pointers, output parameters, and delegates (similar to C's function pointers), whereas Java cannot do those things.
However, C# is not more advanced than C++. Like Java, C# is far less powerful and less complex than C++. All 3 languages really target different areas of software development, comparing them is really apples and oranges once you get beyond their ancestory.
|
|
|
|
|
|
Of course C# is evolution of C++, but C++ is one of the greatest programme language.
=========================================
中国,昆明
|
|
|
|
|
C# is an evolution from several previous languages. Quite a bit Java, lots of C++ and some Pascal, mostly.
In some ways C# is more advanced than C++. The memory management for example is more advanced. It's much more efficient, but also less predictable. It's better for most purposes, but there is still a few applications where you rather want the simple, straight forward, predictable memory management of C++ instead.
---
It's amazing to see how much work some people will go through just to avoid a little bit of work.
|
|
|
|
|
|
It seems you're using the index of the user in the ArrayList as an access key. You may be better off just storing a reference to the user. That way, you can use any type of collection (although an ArrayList is quite suitable) to store the users.
/ravi
|
|
|
|
|
|
Instead of keeping track of an int that's the index into the ArrayList , just keep track of the object (presumably a User ) that you added to the ArrayList . That way you can check if the user is still connected by using Contains() rather than accessing an index that may be invalid.
/ravi
|
|
|
|
|
Oh... So like, assign a user some kind of unique ID or something and pass that to my overridden Contains() ? Thanks!
Windows Calculator told me I will die at 28.
|
|
|
|
|
Yes, that will definitely work and is a common way of checking for the presence of objects.
/ravi
|
|
|
|
|
OK, thanks very much!
Windows Calculator told me I will die at 28.
|
|
|
|
|
I looked all over the web for an easy way to read an XML file, with no success. Most places I found used the XmlTextReader.Read() method, which I don't find easy to use if I dont wanna go thru the whole file.
This is what I am looking for. Say I have the following XML file:
<city name="New York">
<population>10,000,000</population>
<growth>1.2</growth>
</city>
<city name="Miami">
<population>7,000,000</population>
<growth>2.4</growth>
</city>
and I would like to access Miami's population element (and get the 7,000,000 string) something like this (I have invent the names of the methods - the final question follows these exampls):
string PopulationOfMiami = xmlfile["Miami"].population;
or perhaps:
string PopulationOfMiami = xmlfile["Miami"].population.value;
or perhaps:
string PopulationOfMiami = xmlfile["Miami"].ElementSon("population").value;
or perhaps:
string PopulationOfMiami = xmlfile.findNameAttribute("Miami").population.value;
I want access to my XML file in a similar form in one of the above fashioned-way. Does anyone know of real methods and class that work like above? I hope I explained myself OK .
Thanks,
Yoni
|
|
|
|
|
|
It looks like you should actually be using XmlDocument, rather than XmlTextReader. That will let you access your data similar to what you're looking for.
XmlDocument doc = new XmlDocument();
doc.LoadXml(yourXML);
String PopOfMiami = doc.SelectSingleNode("/cities/city[@name='Miami']/population").InnerText;
Alternately, you can create an XML serializer, which would give you syntax closer to what you're looking for.
--------------
TTFN - Kent
|
|
|
|
|
Thanks - this looks like what I was looking for. Problem is that I have a problem:
My XML is a file, not a string variable. i.e. this doesn't work:
XmlDocument doc = new XmlDocument();
doc.LoadXml(@"c:\myfile.xml");
String PopOfMiami = doc.SelectSingleNode("/cities/city[@name='Miami']/population").InnerText;
I looked around for a way around this, trying to give LoadXml a XmlReader and XmlTextReader, but nothing. How can I load my XML file and then do the select?
Thanks,
Yoni
|
|
|
|
|
If the XML is in a file use doc.Load(path) instead.
--------------
TTFN - Kent
|
|
|
|
|
Thanks. New problem
I get a "XmlException: '?' is an unexpected token. Expecting white space" exception. doh. Any ideas?
Thanks again,
Yoni
|
|
|
|
|
What does your XML look like?
-- modified at 14:52 Tuesday 12th December, 2006
As in, it's not just the six lines above, is it?
--------------
TTFN - Kent
|
|
|
|
|
No, it isn't just six lines. It's similar tho - many more cities and many more elements. Now that you mention it - it has a first line:
<?xml version="1.0" encoding="ISO-8859-1"?>
Could it be this?
-- modified at 21:29 Tuesday 12th December, 2006
|
|
|
|
|
No, that's a fairly standard XML declaration. However, I'm guessing there's some high-ASCII character somewhere in that document, or something sitting in the wrong place. Does the error message come with a position (something along the lines of "The expected token is 'whitespace'. Line 1, position 40. )
--------------
TTFN - Kent
|
|
|
|
|
ahhh Thanks! Indeed - it did have a position - I looked it up in the XML and found a name with a quote in it I'll escape it.
Many thanks,
Yoni
|
|
|
|
|
Hi,
There is another way which you can read the values of XML file. Given below the code.
1. In the XML file, add the lines as below:
CityNY name="New York" population=10,000,000 growth=1.2
CityMi name="Miami" population=7,000,000 growth=2.4
2. Open a new class called ReadXMLConfig
3. use the namespace, using System.Xml;
4. Declare the data members as follows :
public class ReadXMLConfig
{
XMLDocument xmlDoc;
private string NYName;
private string NYpop;
private string NYgrowth;
private string MiName;
private string Mipop;
private string Migrowth;
}
5. Type the following in the constructor area:
xmlDoc=new XmlDocument // in the constructor
NYName = null;
NYpop = null;
NYgrowth = null;
MiName=null;
Mipop=null;
migrowth=null;
6. Create a function called LoadXML and type as follows:
public void LoadXML()
{
xmlDoc.Load("XMLFilename");
XmlNodeList elemList;
XmlElement elem;
elemList = xmlDoc.GetElementsByTagName("CityNY");
elem = (XmlElement)elemList[0];
NYName = elem.GetAttribute("name");
NYpop = elem.GetAttribute("population");
NYgrowth = elem.GetAttribte("growth");
elemList = xmlDoc.GetElementsByTagName("CityMi");
elem = (XmlElement)elemList[0];
MiName = elem.GetAttribute("name");
Mipop = elem.GetAttribute("population");
Migrowth = elem.GetAttribte("growth");
}
Call this load function wherever you want.
Hope this will helps.
Cheers
-- modified at 4:24 Tuesday 12th December, 2006
Meeram395
|
|
|
|
|
Thanks, but I can't change the XML so easily - I found a VB code on the net that converts an excel file to an xml file. It isn't flexible. the city tags represent a row in an excel. can't rename them.
Thanks anyway, I might use this in the future.
Yoni
|
|
|
|
|
I have a function that takes a string in html format and print it ona printer in my small windows c# program. I am wondering how can i add print preview functionality to this. I have no clue.
To print a richTextbox i just used like that, but this is a webbroweser control.
thanks
printpreivewDialog pp = new printpreivewDialog();
pp.document=doc;
pp.ShowDialog();
public void PrintHtml(string sHtml,bool bPromt)
{
frmObj.axD.DocumentHTML=sHtml;
for(;frmObj.axD.Busy!=false;)
{
System.Windows.Forms.Application.DoEvents();
}
object opt=null;
if (bPromt)
opt="1";
frmObj.axD.PrintDocument(ref opt);
}
|
|
|
|