|
Hey guys.
I just started a new job which requires C# skills so I'm trying to get myself up to speed and while I've been able to understand most of the stuff so far, one thing I don't understand is what is the purpose of the ":" and everything after it when creating a class?
For example, what does the ":" mean in the following line and what is the purpose for "ExcelReport, IReport":
------------------------------------------------
public class SampleClass: ExcelReport, IReport
-------------------------------------------------
This code is basically from one of their applications. It writes a report to an excel file.
Oh, also if it's not too much trouble, can anyone explain what ":base()" is used for? For example:
---------------------------------------
public SampleClass(FileInfo fileName)
: base(fileName)
---------------------------------------
Thanks again guys.
-Goalie35
-- modified at 9:02 Thursday 10th August, 2006
|
|
|
|
|
inheritance
SampleClass is inherited from ExcelReport.
:Base(fileName) calls the constructor of the base class.
Hope this helps.
I've found a living worth working for, but I haven't found work worth living for.
<marquee>
|
|
|
|
|
The : in the class declaration indicates that your class will inherite from some other class. In the example you gave:
public class SampleClass: ExcelReport, IReport
SampleClass inherits from the class ExcelReport, and the interface IReport.
Roy.
|
|
|
|
|
Other have provided the correct answer but I must recommend purchasing a book on C# if you are at this level of newness. Many of these sort of questions will be covered ad naseum in the first few chapters catapulting you ahead of your peers (assuming you asked them and they didn't know either)
Not only will you have the what but you will have the why.
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
I would agree with Ennis on getting yourself a book. I would suggest that you may want to splurge on two books:
Get a small book to get a quick overview of C#.
Then a detailed one that goes into everything there is to know.
Once you feel comfortable, get yourself the Design Patterns in C# book as this will become your development bible.
When you do inheritance you can inherit an interface ( public interface ISomething ) and you can inherit an abstract class or inheritable class ( public abstract class Something or public class Something ).
You can only inherit a single object and that must be the first name in your list after ':'. All others must be interfaces. This is called single inheritance. The benefits of inheritance is that you automatically gain the methods the original class already had written and tested. (which means you may not have to)
If you want to change or add behavior you then override a method and add your own code. Calling base.Method() either in the method signature or in your method is how you execute the code your program is hiding from users of your program. So if you see something like this:
public override bool MyOveridableMethod(string parm, bool state)
:base(parm,state)
{
}
then the developer wants the base method to execute first before executing his own code. If you see code like this:
public override bool MyOveridableMethod(string parm, bool state)
{
....
}
then the developer wants to control when (or if) the underlying code is executed.
If this description totally loses you, then it is further proof you really need to do some reading. But you will absorb it and in a few months it will all start to sound like common English.
-- modified at 16:33 Thursday 10th August, 2006
|
|
|
|
|
Im going to have to ask for both n's in Ennis for obvious reasons. The two are pronounced entirely different and misspelling lead to humourous consequences.
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
So sorry. It is modified so no one will read it with a long E.
|
|
|
|
|
hi friends, i have made a client/server application using socket connection.
now i have a problem like how to transfer the data between client and server.
can anybody help me?
|
|
|
|
|
hi,
Try this code
<code>
//Server
Socket server = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
server.Bind(new IPEndPoint(IPAddress.Any,20000));
m_tcpListener.Listen(50);
Socket client = server.Accept(); // wait for a client to connect
string message = "Testing 1,2,3";
client.Send(Encoding.ASCII.GetBytes(message));
client.Shutdown(SocketShutdown.Both);
client.Close();
server.Close();
//Client
Socket client = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
client.Connect(new IPEndPoint(Dns.Resolve("127.0.0.1").AddressList[0],1000));
byte []buffer = new byte[1024];
int read = client.Receive(buffer);
Console.WriteLine(Encoding.ASCII.GetString(buffer,0,read));
</code>
It's just a simple example in which a server waits for a client to connect then sends to the client a message, and the client prints the received message. Hope it's a start for you.
Do your best to be the best
|
|
|
|
|
hi karkster
thankyou for your reply. I am doing a project on media player. i want to transfer the music files between the client and server. can you suggest me how to transfer the playlist from client to server.
Thankyou.
|
|
|
|
|
Hi,
To send a file to the client you just need to do this:
<br />
FileStream fstream = File.Open(filename,FileMode.Open);<br />
byte []buffer = new byte[fstream.Length];<br />
fstream.Read(buffer,0,buffer.Length);<br />
fstream.Close();<br />
Use the buffer instead of the Encoding.ASCII.GetBytes(). The sockets send and receive byte arrays.
Do your best to be the best
|
|
|
|
|
hi all,i need to search the word present in the word document (this word document is present in the aplication domain).Is it possible...how to do this.....
ayyp
|
|
|
|
|
depends on the size of the document, either read it line by line or load the entire text and search for the word in question
String.Contains("SearchWord")
only two letters away from being an asset
|
|
|
|
|
it through error like "'string' does not contain a definition for 'Contains'"
here is my code:
StreamReader sr=new StreamReader("...\\...doc");
string s1=sr.ReadToEnd();
s1.Contains("word");
ayyp
|
|
|
|
|
you need to read on msdn for this command
Word.Find fnd = ThisApplication.Selection.Find;
|
|
|
|
|
Hi,
Using V2005;
One of the first methods I run is checking the existance of essential files - particularly in my case the database file. If it doesn't exist I pop up a message box alerting the user and then when they click OK the program should exit ie:
private void startupCheck()<br />
{<br />
bool dataBaseExists;<br />
dataBaseExists = File.Exists(@".\Resources\myclub.mdb");<br />
if (dataBaseExists == false)<br />
{<br />
MessageBox.Show("The database file is missing from the Resource Directory.\nPlease install database file and start program again", "WARNING - CRUCIAL FILE MISSING", MessageBoxButtons.OK, MessageBoxIcon.Stop);<br />
exitProgram;<br />
}<br />
}
Problem is that program flow returns to program.cs and then crashes. User is then given the option to debug etc.
How can I get the program to gracefully exit and not leave the user panicing?
Glen Harvy
|
|
|
|
|
What is exitProgram? Call Application.Exit after the MessageBox
only two letters away from being an asset
|
|
|
|
|
Glen Harvy wrote: and then crashes
What does that mean exactly? Are you getting any exception?
When do you call startupCheck?
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Thanks for your response:
Stefan Troschütz wrote:
What does that mean exactly? Are you getting any exception?
After the program makes the test and exits (see below) I get ->
The error is:
Microsoft .Net Framework
Unhandled Exception has occured in your application ...
Could not find file ......
I then click Quit and get a further message saying that "Program has encountered a problem and needs to close ....
Stefan Troschütz wrote: When do you call startupCheck?
program.cs contains
static void Main()<br />
{<br />
Application.EnableVisualStyles();<br />
Application.SetCompatibleTextRenderingDefault(false);<br />
Application.Run(new MainForm());<br />
^^^^^^^^^^^^^^^^^^^^^^^^^^^^<br />
When debugging this is where the debugger goes after the call to Application.Exit()<br />
<br />
}
and MainForm.cs contains (in part) ->
bool startupCheckValue = true;<br />
startupCheckValue = startupCheck();<br />
if (startupCheckValue == false)<br />
{<br />
Application.Exit();<br />
}
and ..
private bool startupCheck()<br />
{<br />
bool dataBaseExists;<br />
dataBaseExists = File.Exists(@".\Resources\myclub.mdb");<br />
if (dataBaseExists == false)<br />
{<br />
MessageBox.Show("The database file is missing from the Resource Directory.\nPlease install database file and start program again", "WARNING - CRUCIAL FILE MISSING", MessageBoxButtons.OK, MessageBoxIcon.Stop);<br />
return false;<br />
}<br />
return true; <br />
}
I've changed the code a bit as a result of the other suggestions made (and well appreciated I might add ) but my original problem still exists .
I think the Application.Exit() is being called at the wrong place however I don't see where else it would go as it's imediately before where the program will spit the dummy anyhow because of the missing file.
Regards,
Glen Harvy
|
|
|
|
|
Glen Harvy wrote: I think the Application.Exit() is being called at the wrong place
Think so to, but unfortunately your post doesn't at which point of the creation process of your MainForm you do the startupcheck. Try putting it into an event handler of the Load event. I think inside the constructor Application.Exit has no effect or crashes the application respectively, as the call to Application.Run hasn't finished or more precisely wasn't yet made. Alternatively you could also make the startup check inside Program.cs:
static void Main()
{
if (!startupCheck())
return;
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
change startupCheck to private bool startupCheck() and have it return true or false. If false never start the application message pump.
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
Thanks for your tip.
It is a much better way of programming and have taken your advice however the Application.Exit() still produces my same problem.
See my other response.
Regards,
Glen Harvy
|
|
|
|
|
Like Mark says, Application.Exit I think is the best way to go.
-Daniel
Typing too fast fro my owngood
|
|
|
|
|
Hi,
I have a requirement to implement WebServices Client in C# and WebServices Server in Java(webSphere). The application involves uploading attachments. Preliminary research suggest I use MTOM, but the webSphere app server I am going to be using does not support MTOM. I have to restrict my ideas towards either MIME or DIME. Please suggest best approach with the mentioned constraints...any sample code with the interop(C# <-> Java) would be appreciated.
Thanks in advance.
Cheers,
Sridhar.
sridhar
|
|
|
|
|
Hi,
I want to debug my SP in SQL server 2005 but i cant find the option for that, just like in SQL2000. Can someone tell me the way i can do that?
Help please,
ankit
|
|
|
|