|
Thanks led mike,
I appreciate your help.
regards,
George
|
|
|
|
|
An abstract class is a special kind of class that cannot be instantiated.No funciton definition can be done in these type of classes.
So what's the advantaghe to incorporate these kind of classes in our project?
If you have an apple & I have an apple and we exchange our apples, then each of us will still have only one apple but if you have an idea & I have an idea and we exchange our ideas, then each of us will have two ideas!
|
|
|
|
|
As a base class.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
This is further to ur reply.
If i say , what's the need of such a base class , which doesnot have funciton definition , only contains funciton declaration.
I can also create such class , where i am defining the funcitons , further , i can override the base class functions , if needed.
Sir , Isn't that ?
If you have an apple & I have an apple and we exchange our apples, then each of us will still have only one apple but if you have an idea & I have an idea and we exchange our ideas, then each of us will have two ideas!
|
|
|
|
|
For example, I wrote a paint program. All my paint tools derived from a Tool class. Tool is not useful, it merely defines the base. So, I don't want to be able to create Tool, only it's derived classes.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Pankaj Garg wrote: No funciton definition can be done in these type of classes.
What do you mean? It's quite possible to have methods and properties in the abstract class. The only limitation is that it cannot be instantiated. As previously stated you use them as base classes that can contain common functionality that all derived classes need/can make use of.
|
|
|
|
|
In addition to the answers already given, read up on Polymorphism[^] as it relates to OOP.
|
|
|
|
|
The abstract keyword is for classes which forms the base for other classes, but does not implement full functionality by itself. You can look at it as a safety net of sorts.
--
Kein Mitleid Für Die Mehrheit
|
|
|
|
|
Jörgen Sigvardsson wrote: but does not implement full functionality by itself
They usually don't, but they may.
|
|
|
|
|
Pankaj Garg wrote: An abstract class is a special kind of class that cannot be instantiated.
Correct.
Pankaj Garg wrote: No funciton definition can be done in these type of classes.
That is not correct.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Pankaj Garg wrote: you have an idea & I have an idea and we exchange our ideas, then each of us will have two ideas!
But if you (for instance, don't take it personally) have a bad idea and tell me about it, and I give you back a better idea, we both end up with one idea. (Both instances of the bad idea get garbage collected.)
|
|
|
|
|
Yes,thats right you can make a class that its fundamental for other classes but you cant declare variable at this class you can use of it as parent class.
|
|
|
|
|
Helllo,
how can i create a notification in the system tray. this messsage should indicate that a new available update exists.
thanks
dghdfghdfghdfghdgh
|
|
|
|
|
You never bother to use google do you? :P
|
|
|
|
|
Normally, I wouldn't do this - but please read this[^] article, and act on it. You really need to follow the guidelines in the article (especially point 1 of the Content section).
|
|
|
|
|
Hi
I have written this code in web based form for checkListBox and getting
"chkListAttribute.Items[iCount].Selected" AS true/false value
but while using this in WINDOWS APPLICATION i am not getting
"chkListAttribute.Items[iCount].Selected" (DOT Selected) .
How can I do this by this process.Please help
for (int iCount = 0; iCount < chkListAttribute.Items.Count; iCount++)
{
if (chkListAttribute.Items[iCount].Selected == true)
{
if (chkListAttribute.Items.Count == 0)
-- do something
else
-- do something
}
}
Thanks In Advance
Amitava
|
|
|
|
|
The System.Windows.Forms.CheckedListbox contains the following properties that you can use to find out what nodes are selected:
.SelectedIndex
.SelectedIndices
.SelectedItem
.SelectedItems
.SelectedValue
If you want to find out which ones are checked you should use any of the following:
.CheckedIndices
.CheckedItems
|
|
|
|
|
Hi right now i am using the following code, every thing is fine, but i am not getting the print content from the jobs in PrintQueue. Any one can help me or suggest me how can i read the content (print document data).
Always the "bPrintData" shows ZERO bytes length
Thanks in advance. This is very very urgent to me..
--Krishna
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Management;
using System.Net;
using System.IO;
using System.Printing;
using System.Collections;
namespace ManagingPrinterJobs
{
public partial class Form1 : Form
{
private PrintServer localPrintServer;
private PrintQueue defaultPrintQueue;
private Hashtable printJobsList1;
private Hashtable printJobsList2;
private PrintJobInfoCollection jobs;
delegate void ScheduleJobs_Delegate(object sender, System.Timers.ElapsedEventArgs e);
private System.Timers.Timer JobScheduleTimer = new System.Timers.Timer(1);
private PrintQueueStream prtQueStream;
private String sPrintJob = String.Empty;
private byte[] bPrintData;
private void Form1_Load(object sender, EventArgs e)
{
//localPrintServer = new LocalPrintServer();
PrintServer localPrintServer = new PrintServer("HP LaserJet 5000");
defaultPrintQueue = LocalPrintServer.GetDefaultPrintQueue();
printJobsList1=new Hashtable();
printJobsList2=new Hashtable();
JobScheduleTimer.Elapsed += new System.Timers.ElapsedEventHandler(ScheduleJobs);
JobScheduleTimer.Start();
jobs = defaultPrintQueue.GetPrintJobInfoCollection();
foreach (PrintSystemJobInfo job in jobs)
{ printJobsList2.Add(job.JobIdentifier, job.Name); }
}
private void ScheduleJobs(object sender, System.Timers.ElapsedEventArgs e)
{
try
{
//if (textBox1.InvokeRequired)
//{
// ScheduleJobs_Delegate Delegate = new ScheduleJobs_Delegate(ScheduleJobs);
// textBox1.Invoke(Delegate);
//}
//else
//{
defaultPrintQueue = LocalPrintServer.GetDefaultPrintQueue();
jobs = defaultPrintQueue.GetPrintJobInfoCollection();
foreach (PrintSystemJobInfo job in jobs)
{
if (!printJobsList2.Contains(job.JobIdentifier))
{
if (!printJobsList1.Contains(job.JobIdentifier))
{
job.Pause();
printJobsList1.Add(job.JobIdentifier, job.Name);
PrintQueueStream prtQueStream = new PrintQueueStream(defaultPrintQueue, job.Name, false);
bPrintData = new byte[prtQueStream.Length];
int qty = prtQueStream.Read(bPrintData, 0, Convert.ToInt32(prtQueStream.Length));
if (bPrintData.Length >= 1)
{
for (int i = 0; i <= bPrintData.Length; i++)
{
sPrintJob += Convert.ToChar(bPrintData);
}
}
job.Cancel();
}
}
}
if (sPrintJob != String.Empty)
{ MessageBox.Show(sPrintJob); }
}
}
Krishna Prasad RVS
Microsoft Certified Application Developer (MCAD)
modified on Friday, May 16, 2008 6:50 AM
|
|
|
|
|
Hello everyone,
Here is my code, and it will always output UTF-16 at XML header even if I set the XML declaration to UTF-8.
Here is my code and output.
My questions,
1. How to make UTF-8 in header other than UTF-16?
2. Is the XML string really UTF-16 encoded or UTF-8 encoded? I think in C#, string is always UTF-16 encoded, why do we need a UTF-8 in header?
<?xml version="1.0" encoding="utf-16"?>
<CategoryList a="12345" b="1d5458cd-a070-40cc-a3f4-cf3c394013cc" c="true" />
using System;
using System.Text;
using System.IO;
using System.Xml;
class Test
{
public static void Main()
{
XmlDocument xmlDoc = new XmlDocument();
XmlDeclaration xmlDeclaration = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null);
XmlElement rootNode = xmlDoc.CreateElement("CategoryList");
xmlDoc.InsertBefore(xmlDeclaration, xmlDoc.DocumentElement);
rootNode.SetAttribute("a", "12345");
rootNode.SetAttribute("b", Guid.NewGuid().ToString());
rootNode.SetAttribute("c", "true");
xmlDoc.AppendChild(rootNode);
StringWriter stream = new StringWriter();
xmlDoc.Save(stream);
string content = stream.ToString();
Console.Write(content);
return;
}
}
thanks in advance,
George
|
|
|
|
|
Looking at msdn documenation: http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.createxmldeclaration.aspx[^]
The section about encoding says,
"The value of the encoding attribute. This is the encoding that is used when you save the XmlDocument to a file or a stream; therefore, it must be set to a string supported by the Encoding class, otherwise Save fails. If this is nullNothingnullptra null reference (Nothing in Visual Basic) or String.Empty, the Save method does not write an encoding attribute on the XML declaration and therefore the default encoding, UTF-8, is used.
Note: If the XmlDocument is saved to either a TextWriter or an XmlTextWriter, this encoding value is discarded. Instead, the encoding of the TextWriter or the XmlTextWriter is used. This ensures that the XML written out can be read back using the correct encoding. "
So I would guess that the "note" applies in your case. Your StringWriter that you are saving to is causing the encoding value to be ignored. (I imagine that the underlying StringBuilder is using UTF-16 strings)
If you were to use the XmlTextWriter, then you can specify the encoding that you want.
|
|
|
|
|
Great wmba!
I studied it. And I think the following statements applies to my issue, right?
--------------------
Note: If the XmlDocument is saved to either a TextWriter or an XmlTextWriter, this encoding value is discarded. Instead, the encoding of the TextWriter or the XmlTextWriter is used. This ensures that the XML written out can be read back using the correct encoding. "
--------------------
But It only mentions TextWriter and XmlTextWriter, which will be able to use their own encoding approach, but I am using StringWriter, it is not mentioned in the document, right?
regards,
George
|
|
|
|
|
|
Thanks wmba,
1.
I have solved this issue from your help. Here is my code. Could you review whether it is correct please?
using System;
using System.Text;
using System.IO;
using System.Xml;
class FSOpenWrite
{
public static void Main()
{
StringWriter stream = new StringWriter();
XmlTextWriter writer = new XmlTextWriter(stream);
writer.WriteStartElement("Stock");
writer.WriteAttributeString("Symbol", "123");
writer.WriteElementString("Price", "456");
writer.WriteElementString("Change", "abc");
writer.WriteElementString("Volume", "edd");
writer.WriteEndElement();
string content = stream.ToString();
return;
}
}
2.
Why in my original code in question, even if I set UTF-16, but I can only use UTF-8 encoding?
regards,
George
|
|
|
|
|
With your code sample, you are missing the part to tells the XmlTextWriter what encoding to use. If you use any class that is derived from a TextWriter (like StringWriter), then you can't specify the encoding. The reason for this is that the base string in a StringWriter is UTF-16, so you have no options for using a different Encoding.
If however, you use a MemoryStream, or something derived directly from Stream, then you can specify a different Encoding.
Anyway, here is a code snippet that describes this:
MemoryStream ms = new MemoryStream();
XmlTextWriter writer = new XmlTextWriter(ms, Encoding.UTF8);
writer.Formatting = Formatting.Indented;
writer.WriteStartDocument();
writer.WriteStartElement("Stock");
writer.WriteAttributeString("Symbol", "123");
writer.WriteElementString("Price", "456");
writer.WriteElementString("Change", "abc");
writer.WriteElementString("Volume", "edd");
writer.WriteEndElement();
writer.Flush();
ms.Seek(0, SeekOrigin.Begin);
StreamReader sr = new StreamReader(ms);
string content = sr.ReadToEnd();
Console.WriteLine(content);
return;
It is important to note that you could have used a similar technique in your original code when you used the XmlDocument.
The reason why you were getting the UTF-16 encoding is because your underlying writer class was a string. StringWriter writes directly to a string (or possibly a StringBuilder). And because strings in .NET are all UTF-16, that is the encoding you got.
When you write directly to a stream (FileStream, MemoryStream, etc), then you are not writing to a string, but conceptually you are writing to just an array of bytes. Because of that you can specify a different encoding.
Anyway, I hope this helps you out.
|
|
|
|
|