|
It is not a weakness of the language - It is a strength of the language.
Since I* am a newbie to c# I do not undersatand how it is a strength.
Can you please kindly explain?
I will be very thankful to you.
|
|
|
|
|
Just use
const string myStr = "text";
-Larantz-
|
|
|
|
|
abhijit pai wrote: I do not undersatand how it is a strength.
Can you please kindly explain?
It is a strength because it forces you to use proper language constructs and to put strings and other values in to const s
For example in C++ you could put
#define MY_STRING "my_string"
SomeFunction(MY_STRING);
or worse
#define MY_INT 5+5
SomeFunction(MY_INT*MY_INT);
which expands out to SomeFunction(5+5*5+5); which is equivalent to SomeFunction(35); and not SomeFunction(100); which some might be expected.
in C# you put
const MY_STRING = "my_string"; or
const MY_INT = 5+5;
When you call SomeFunction(MY_INT*MY_INT) you get a value that makes sense.
using const s in C# is also type safe. So the compiler can show you easily what the problem is, if there is one. Preprocessor statements like #define are naturally evaluated before the compiler runs. This means that in C++ the defined values are expanded out in advance. If the compiler has a problem with some code it can only show you the expanded version, which may look quite different to the version you see in the IDE, since it never sees the version you see.
Does this help?
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
My: Website | Blog
|
|
|
|
|
it does help alot, but I would be thankful to u if can please provide more clarity on it or some link that would make it undersand me in depth.
|
|
|
|
|
What is to understand, it is a not supported feature - Use const s.
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
My: Website | Blog
|
|
|
|
|
Hi friends,
I want to develop file monitoring system where I want to track down the files created by perticular process. I tried using FileSystemWatcher class to monitor drives\directories. But when any event occurs FileSysteWatcher fails to give any information about that process that has created/changed/deleted that file. It would be nice if somebody can help how to achieve this using c#!! Or I have to use some win32 apis to get this done? if so does anybody know about these APIs?
Hiren Suchak
-- modified at 1:52 Friday 26th May, 2006
|
|
|
|
|
To get the active sqlserver names
|
|
|
|
|
when i open a file stream, is it possible to start reading a specific line other than reading from the beginning to end?
|
|
|
|
|
No. The library has no way of knowing what a line is without walking through them, a newline is just another character ( well, two, but it's just data, there's no index ).
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
hi
i want to collect many files and create password protected self-extract file. how to do that ?
thanks ?
|
|
|
|
|
i called stored procedure that has variable output like "@ss int output"
but i couldn't collect value of that variable in c# i use 'executenonguery'
shoud i use another thing!! i don't know if any one can help me i'll be glade..
|
|
|
|
|
|
You can set the Direction property of an SQL Parameter object to ParameterDirection.Output if you're requiring output.
command = new SqlCommand(...);
SqlParameter outputParam = new SqlParameter("@ss", 0);
outputParam.Direction = ParameterDirection.Output;
command.Parameters.Add(outputParam);
command.ExecuteNonQuery();
int returnValue = (int)outputParam.Value;
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Goof around music jam with my brothers (with video)
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
i fill 1 data table from database . i have 1 datagrid on the form that i fill it manually. can i add one of the columns of the data table to my datagrid?
thank you
|
|
|
|
|
Yes you can, add a new column to the datasource (DataTable??) which you are creating manually and fill data in that newly added column from datatable filled from database.
Saqib
|
|
|
|
|
I created a global hotkey (Alt + F) using the RegisterHotKey API and then in WndProc caught the WM_HOTKEY message and then started a keyboard hook which blocks all keys typed from reaching other applications. (The point of this was so I could press alt+f type in a command and press enter to execute whatever app or website that's associated with the command.) The hook is started using the SetWindowsHookEx API with a delagte pointing to a procedure that catches WM_KEYDOWN and WM_KEYUP message. (Based on the code found at http://www.codeproject.com/csharp/globalhook.asp[^])
My problem is that after stoping the hook the 'alt' key is still in it's keydown state (I'm guessing that the hook ate the keyup message instead of sending it back) so pressing keys on the keyboard will access the menu or whatever other hotkeys there are. I've tried sending a WM_KEYUP message (using SendMessage API) for the alt key after the hook was stopped, but it didn't work. I wasn't sure of what window handle to send it to for a hotkey or if it even matters (I used the main form of which the hotkey was registed with).
Thanks
Blake
|
|
|
|
|
Hi,
I am writing a multihread app in C# 2003. There is unmanaged dll in it.
When GC activates after memory reaches the some level of fullness,an exception is thrown. It is access violation exception from mscorwks.dll and application crashes.
If someone has an idea about it, it would be really helpful.
Best regards
asbasir
|
|
|
|
|
Hi,
I would like to find out how to append a bitmap to an existing bitmap in .net 2.0. I am programming in C++/CLI but C# code will also be fine.
What I am trying to accomplish is a 'Render to Disk' feature, where I can create a very large bitmap image on disk by appending a 'strip' at a time to the bottom of the image; thus growing the bitmap on the disk.
I have tried using the SaveAdd method, but have been unsucessful. Is this the right approach or am I barking up the wrong tree? Here is some code that I tried:
EncoderParameters^ params = gcnew EncoderParameters(1);
params->Param[0] = gcnew EncoderParameter(Encoder::ColorDepth, (short)32);
saveBitmap->Save(saveBitmapDialog->FileName, codec, params);
saveBitmap->SaveAdd(params);
The Save method works fine and results in a bitmap on disk, but SaveAdd fails. Any ideas would be greatly appreciated, there does not seem to be much info about this on the net.
Thanks!
zenzero
|
|
|
|
|
The SaveAdd method is used to add a frame to a multi-frame image, not to write a part of a larger image.
There is nothing in the framework to support partial writing of a large image. You have to do it by hand.
Look into the bitmap file format. There is no compression so the file format is fairly simple.
You have to specify how large the final image will be when you write the file header to the file.
One thing that might cause you some problem is that bitmap images are stored upside down...
---
b { font-weight: normal; }
|
|
|
|
|
Thanks for that Guffa. I know not to waste any more time with SaveAdd !
I tried the old fashioned way before but couldn't get it to work, but that was probably because I wrote the wrong size to the file header. I would just see a single strip visible yet the file size would indicate that all the data was there.
Thanks for the illumination,
zenzero
|
|
|
|
|
Hello,
I want to use multiple queries (so, in the while-loop of a reader, i want to use another query + reader).
The folowwing code will give an example:
<br />
SqlCommand myCommand = new SqlCommand("SELECT date, customerid FROM orders ORDER BY date ASC", connect);<br />
SqlDataReader myReader = myCommand.ExecuteReader();<br />
while (myReader.Read())<br />
{<br />
SqlCommand myCommand2 = new SqlCommand("SELECT customer FROM customers WHERE id = " + myReader["customerid"] + " ORDER BY date ASC", connect);<br />
SqlDataReader myReader2 = myCommand2.ExecuteReader();<br />
while (myReader2.Read())<br />
listBestellingen.Items.Add(myReader["date"] + " " + myReader2["customer"]);<br />
}<br />
myReader.Close();<br />
But he sais i allready have a reader open (which is the truth), and that i have to close it, but that's a no can do)..
Can somebody help me?
Thanks!
-- modified at 16:20 Thursday 25th May, 2006
|
|
|
|
|
A datareader keeps the connection open exclusively for the duration of its read operation.
There are 2 ways to rectify this:
1. use another connection for the second datareader
2. Read the contents of first datareader into an arraylist, close the datareader and then use the same connection for the second datareader (recommended).
With Regards
Shane Sukul
BSc Mcsd.Net Mcsd Mcad
.Net Architect/Developer
Ashlen Consulting Services P/L
|
|
|
|
|
Or a third option to produce a better SQL command that only requires one reader.
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
My: Website | Blog
|
|
|
|
|
You can only have one active reader per connection. You must open a new connection to run two readers simultaneously on the same database. You also don't close your second reader which means it won't get closed until the garbage collector cleans it up - and that may not be for a long time.
However, you can do all this with one SQL command:
SELECT orders.[date], cusomter.customer
FROM orders
INNER JOIN customer ON orders.customerid = customer.id
ORDER BY [date] ASC
So your code would look like this:
SqlCommand = myCommand = new SqlCommand("SELECT orders.[date], cusomter.customer"+
"FROM orders INNER JOIN customer ON orders.customerid = customer.id ORDER BY [date] ASC";
SqlDataReader myReader = myCommand.ExecuteReader();
while(myReader.Read())
{
listBestellingen.Items.Add(myReader["date"] + " " + myReader["customer"]);
}
myReader.Close();
Does this help?
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
My: Website | Blog
|
|
|
|
|