|
Can we have a parametrised constructor in a static class?
|
|
|
|
|
Basically no. Static classes cannot have public constructors (any access modifier i.e public or private, in fact), and static constructors cannot have parameters.
Hope this helps
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
No. How would you call it? Static constructors are called by the framework at a time which your code can't know*, and without any parameters. In fact the same construct in Java makes this clearer by just being
static {
}
... so it doesn't look like a callable method (which it isn't).
(*: It's called the first time the class is fully loaded, which I think happens when a method/field/property is called. However, you still don't know when that is because some other code might use the same class.)
If you want to preload state then you can have a parameter-accepting normal static method which you call in the Main procedure or via a static constructor elsewhere. (Obviously, you could call it from anywhere, but you want to call it before you are going to use the class at all, and Main is about the only place you can guarantee that.)
|
|
|
|
|
No. Is that a homework question or is there a problem you're trying to solve? If the latter, what are you trying to solve?
|
|
|
|
|
We can have a constrictor in a static class (thought not a parameterized one).
Read more about this here[^].
|
|
|
|
|
Abhinav S wrote: We can have a constrictor in a static class
Does that narrow the scope of variables?
[Edit]Univote countered.
modified 11-Sep-12 14:12pm.
|
|
|
|
|
No. Think about it. You need to have the static initialized when an instance of a class is created.
|
|
|
|
|
i have a problem in my code for doing the slectedindex event.pls help
SqlCommand cmd = new SqlCommand("select firstname,phoneno from user1 where rollno='" + comboBox1.SelectedItem + "'", con);
SqlDataReader dr;
con.Open();
dr = cmd.ExecuteReader();
if (dr.Read())
{
textBox1.Text = dr[0].ToString();
textBox2.Text = dr[1].ToString();
label4.Visible = true;
label4.Text = "show";
}
con.Close();
|
|
|
|
|
What error are you getting ?
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
Null Reference Exception?
When you select a different value in a ComboBox, the previous element gets de-selected, causing a SelectedIndexChanged event. Now, nothing is selected, the SelectedIndex is -1. Next, the element you selected gets selected, causing the next SelectedIndexChanged event. And now it is really selected, and you can use it.
|
|
|
|
|
Hi
I want to use windows login box in my c# application which is secure and pass values using tokens. I do not want to create a custom login box. How to popup the login screen?
Thanks in advance,
Sai
|
|
|
|
|
|
Thank you very much ...
|
|
|
|
|
|
Is this a custom built? I do not want to use custom built. I did one myself using Active directory directory service reference and the company do not want it.
Thank you,
Sai
|
|
|
|
|
I have a web service stack trace where the method is called GetLoadTrace();
However, I can't seem to find what line the error occured in . Does the stack trace tell you ?
It just says GetLoadTrace()+90
GetLoadTrace()+155
What line did the error occur on then ? Does it NOT tell you ?
==================================================
--I am the STIG !!!!!!!!!!!!!!!!!
|
|
|
|
|
The exception is usually thrown in the method at the very top of the stack trace.
The stack trace does NOT tell you on which line the problem occured in a Release compiled application, only the method in which it occured.
|
|
|
|
|
It's not actually release/debug, it's whether a .pdb file is present ... but I don't think it's possible to make a .pdb for a release build so you can never get line numbers in a release stack trace.
|
|
|
|
|
BobJanova wrote: I don't think it's possible to make a .pdb
You can. A release build is not magic, the main difference is just that the debug version doesn't optimise the code. If you do a release build, take a look in your Release folder - you'll see a number of generated PDB files in there.
To prevent generation of release PDV files, select Project Properties > Build > Advanced > Debug Info: None (make sure the configration is set to Release when you do this).
|
|
|
|
|
Oh, I thought that the optimisations made it too hard for the compiler to know what to create.
If I'm using csc, and I use /debug to create a .pdb, then, is that still 'release' code (i.e. optimised etc)?
|
|
|
|
|
It's not release code if you use csc /debug . If you want to do the release build that you get with Visual Studio, just use csc.exe /optimize+ /debug:pdbonly . To just produce the release build without the pdb, just use csc.exe /optimize+ .
|
|
|
|
|
The compiler will know what to create easy enough.
My problem is with optimizations and code rewrite, are the line numbers going to be accurate??
|
|
|
|
|
I need to create a help file for an application. Not code comments but actual "how to use" help file for end users.
Which "tool" should I use?
Which tool have you used? Did you think it was good? Why?
Which tool shouldnt I use? Why not?
Thanks
bart
|
|
|
|
|
This isn't really an appropriate question for the C# forum. What you could do is download and test some of the help authoring tools to see which best suits your requirements.
|
|
|
|
|
Can you suggest a better forum?
bart
|
|
|
|