|
Abstract class versus Interface[^]
I haven't read the article but it is rated good. In comments, however, is link to Base Class Usage Guidelines[^] (I've read the book) which says that you should favor base class. The reason is, that once you ship interface, you can't extend it without breaking all stuff that implement previous version of interface. You can, however, extend (abstract) base class, without breaking it, as long as added method isn't abstract. (So derived classes dont have problem)
"Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus
"Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe
|
|
|
|
|
thanks again.
Abstract is the way I want to go.
|
|
|
|
|
Hello everyone!
Okay, I have a variable that gets changed to 0 somewhere in my code, and I want to know where.
So I added a variable watch (VS 2005), however, on the watches list, it displays as this with an error icon to the left:
((Server.Client)((new System.Collections.ArrayList.ArrayListDebugView(this.clients)).Items[0])).id <br />
The type name 'Client' does not exist in the type 'Server.Server'
First, I didn't know you could have a type inside another type.
The variable I'm trying to add is public member id of the class Client . Server.Server is a class containing a custom ArrayList of Client s.
Does anyone know why I'm getting that error? Thanks!
Windows Calculator told me I will die at 28.
|
|
|
|
|
Try typing the fully qualified name of Client in the watch window.
|
|
|
|
|
Hi all,
how can I define a struct with a string array (fixed dimension) inside like this:
public struct _ref<br />
{ <br />
public int iId;<br />
public string sDesc;<br />
public string[2] sFields;<br />
}
Thanks in advance,
Marc Soleda
... she said you are the perfect stranger she said baby let's keep it like this... Dire Straits
|
|
|
|
|
public string[] sFields = new string[2];
|
|
|
|
|
Hello everyone,
I have a Button which I have assign a ConextMenu. The ContextMenu with it's options pops up once the user clicks the right mouse on the button. Is it possible to change this so when the user clicks the LEFT mouse the ContextMenu?
Thank you very much for your help and have a great day.
Khoramdin
|
|
|
|
|
Hello,
private void button1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(e.Button == MouseButtons.Left)
{
if(button1.ContextMenu!=null)
{
button1.ContextMenu.Show(button1, new System.Drawing.Point(e.X, e.Y));
}
}
}
All the best,
Martin
|
|
|
|
|
Hi everyone,
How to Get Hardware Information in C sharp ?
Example : HardDisk Drive Serial Number, Volume, Product...
Modem Serial Number, Product....
Thanks !!
|
|
|
|
|
|
|
i have a string s i have convert it to ascii code useing this
Byte[] b = Encoding.ASCII.GetBytes(s);
but the ascii code for english character. and i want it for Arabic character, what is the name of the code and is it available in C#.Net 2005
|
|
|
|
|
Unicode supports virtually all existing characters, so you could use for example UTF-8 encoding. Otherwise you can look in the documentation for the Encoding class for all the supported encodings.
---
single minded; short sighted; long gone;
|
|
|
|
|
Hi..
How to invoke the xsd.exe thru code?..
And also
How do u i know the location in which the visual studio is installed.
Thanks in advance.
N.Navaneethan
|
|
|
|
|
You should be able to use the Process.Start to call it.
Looking at the shortcut from the .net command prompt that knows about the xsd.exe program
It has this for .net 2.0:
%comspec% /k ""C:\Program Files\Microsoft Visual Studio 8\VC\vcvarsall.bat"" x86
and this for .net 1.1:
%comspec% /k "C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\Tools\vsvars32.bat"
So if you call that then you could call the xsd.exe with what ever parameters.
Hope that helps.
Ben
|
|
|
|
|
Hi,...
The installation path need not be c:\...
How do i find the installation path if it is in some other location?
N.Navaneethan
|
|
|
|
|
You just need to start the command shell with those commands. After the command shell is started you can change to any mapped drive you want. The important thing about starting the command shell this way is that the command shell knows what xsd.exe is which is important.
Hope that helps.
Ben
|
|
|
|
|
Hi all. I am not well experienced with the Settings feature on the new VS, and the way it accesses\creates App.config files. But here is a simple one
<configuration>
<configsections>
<sectiongroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<applicationsettings>
<qualitycenter.properties.settings>
<setting name="SqlServerName" serializeas="String">
<value>
<setting name="SqlUserName" serializeas="String">
<value>
<setting name="SqlPassword" serializeas="String">
<value>
You notice that the setting SqlServerName value is empty at the time I built the dll. The dll is a COM application with public interfaces to invoke different windows (Forms). I manually changed the <appname>.dll.config file and specified a name for the SqlServerName. When I invoke my COM app, It does not seem that it is reading my app settings from the config file because the value of the sqlservername is still null. Any one has any ideas about what I am doing wrong.
thx
|
|
|
|
|
I guess it stiped out the sample, but here it is again
<applicationSettings>
<QualityCenter.Properties.Settings>
<setting name="SqlServerName" serializeAs="String">
<value />
</setting>
<setting name="SqlUserName" serializeAs="String">
<value />
</setting>
<setting name="SqlPassword" serializeAs="String">
<value />
</setting>
</QualityCenter.Properties.Settings>
</applicationSettings>
|
|
|
|
|
Hi everyone.
I am on the LAST beginner tutorial on MSDN in C#. I have a couple questions.
I am adding to my database with the code :
this.cd_tableTableAdapter.Insert(cdName, cdDescription, image);
this.cd_tableTableAdapter.Fill(this.cdTrackerDataSet.cd_table);
This is SUPPOSED to write to my database and of course it shows up while the app is running, but it NEVER writes it to the database.
I thought I remember from a previous tutorial that I had to do an actual UPDATE on the database to make sure it got written. Is this correct? Can someone help me permanently write this info to my dbase?
Thanks!
|
|
|
|
|
There are many ways to write data to the db:
With SqlDataAdapter:
FETCH DATA:
SqlConnection con = new SqlConnection( connectionstring);
SqlCommand command = new SqlCommand("select* from table", con);
SqlDataAdapter adapter = new SqlDataAdapter(command);
DataSet set = new DataSet();
adapter.Fill(set);
CHANGE DATA:
//get row to change
DataRow row = set.Select("Columnx = 1");
row("Columnx") = 2;
//Write to DB
adapter.Update(set);
//commit dataset
set.AcceptChanges();
INSERT NEW ROW:
DataRow newrow = set.Tables[0].NewRow();
newrow("Columnx") = x;
newrow("Columny") = y;
set.Tables[0].Rows.Add(newrow);
adapter.Update(set);
set.AcceptChanges();
Connection does not have to be opened nor closed when using adapter.
You can also use direct SQL like so..
SqlConnection con = new SqlConnection( connectionstring);
SqlCommand command = new SqlCommand("insert into table values(1,2) ", con);
con.Open();
command.ExecuteNonQuery();
con.Close();
|
|
|
|
|
I want to make a typewriter like program (you know, writes a string 1 letter at a time), so I tried to use a timer but the timer elapsed event has to be static, so then you don't have access to global variables \=
I tried this but it doesn't work:
<br />
public string myString = "hello all";<br />
public int i=0;<br />
static void Main(string[] args)<br />
{<br />
System.Timers.Timer t = new System.Timers.Timer(200);<br />
t.Elapsed += new System.Timers.ElapsedEventHandler(t_Elapsed);<br />
t.Start();<br />
Console.Read();<br />
}<br />
<br />
static void t_Elapsed(object sender, System.Timers.ElapsedEventArgs e)<br />
{<br />
Program mypr = new Program();<br />
Console.Write(mypr.getString());<br />
mypr.addToI();<br />
}<br />
public string getString()<br />
{<br />
if (i < myString.Length)<br />
return myString[i].ToString();<br />
else<br />
return null;<br />
}<br />
public void addToI()<br />
{<br />
i++;<br />
}<br />
because it creates a new instance of "Program" each time the timer is elapsed =\
so how can I do it?
|
|
|
|
|
Hi,
Hope I didn't missunderstood your problem.
Why not having a static string :
public static string myString = "hello all";
so you have no need of creating a program object
Marc
PS: ElapsedEventHandler do not require a static method
try:
t.Elapsed += new System.Timers.ElapsedEventHandler(this.MyNonStaticMethod);
|
|
|
|
|
Hi.
I'm new to .NET, and I'm writing a logging service that uses .NET remoting. The idea is that the service publishes an EventProcessor object that clients can access via .NET Remoting, passing it DiagnosticEvent objects for processing.
I've altered the main program for the service slightly so that I can run it more easily as a "regular" application during debugging. I have an assembly that contains the "diagnostics" classes that do the work, the service app itself, and a test client app that lets you create a DiagnosticEvent and "dispatch" it.
The problem is that I'm getting errors telling me that the DiagnosticEvent object which I'm passing to the remote object is "not marked for serialization" -- even though it is. When I try adding a function that takes a TestObject, expecting the same error, I then get an exception about "unable to load for deserialization."
I'm clearly missing something basic.
One more little hitch is that I've been wrestling with static initialization of the remote object. It's a singleton class, and it seems that I get messed up if the server application instantiates the class before remote applications get a chance to. But perhaps that's for another post.
Can someone help me clear up my serialization issues? Here's some of the code:
The object I'm passing to the remote object is declared as:
[Serializable]
public class DiagnosticEvent : ISimObject
{ . . . }
...and so is my TestObject:
[Serializable]
public class TestObject
{
public int m_Int;
public string m_String;
}
Here's the code where the remote object is served up:
private static TcpChannel Publish()
{
TcpChannel channel = null;
if (channel == null)
{
// Create an instance of a channel
channel = new TcpChannel(8080);
ChannelServices.RegisterChannel(channel, false);
}
// Register as an available service with the name GEDiag
RemotingConfiguration.RegisterWellKnownServiceType(
typeof(GESim.Diagnostics.EventProcessor),
"GEDiag",
WellKnownObjectMode.Singleton);
return channel;
}
Here's the code where the client connects to the remote object:
private void ConnectToEventProcessor()
{
// Create a channel for communicating w/ a remote object
// Notice no port is specified -- because we're the client.
if (null == s_Channel)
{
s_Channel = new TcpChannel();
ChannelServices.RegisterChannel(s_Channel, false);
}
if (null == m_RemoteEventProcessor)
{
// Create an instance of the remote object
m_RemoteEventProcessor =
(EventProcessor)Activator.GetObject(
typeof(EventProcessor),
"tcp://T00472343:8080/GEDiag");
}
}
...and finally, the code where the remote object is exercised -- both with a TestObject and with the actual DiagnosticEvent object. Neither work, for different reasons:
TestObject testObject = new TestObject();
testObject.m_Int = 45;
testObject.m_String = "Testing 123...";
int i = m_RemoteEventProcessor.Test(testObject);
m_RemoteEventProcessor.EnqueueEvent(theEvent);
I'd be happy to send the solution (I've scultped it down to something minimal).
Thanks, in advance.
Just Mike
|
|
|
|
|
Your problem could be that one of the properties/fields in your DiagnosticEvent class isn't marked as serializable.
Deja View - the feeling that you've seen this post before.
|
|
|
|