|
Ok better idea: initialize it in the constructor.
|
|
|
|
|
That works like a charm. Would you please explain to me what did the static keyword change in this case?
Appreciated,
|
|
|
|
|
It cheated. I'm afraid I suggested an ugly work-around that is at least "bad taste".
Oh well. An explanation.
It made the "temporary" object static. That is, it is shared between all instances of the containing class (or struct). It shouldn't be (shared, that is), but it works.. But it also has the unfortunate side effect that a reference to that array is kept - forever (well, at least for a long time).
I was partially under the impression that this initialization code was for a local variable, if that were true there would be no need of such ugly hacks.
And I should have suggested something better, which I did later.. Initializing that field in the constructor.
Now, I just realized something. Code like that should almost never initialize a non-static field. Because it looks like that (jagged) array is meant to be a look-up table. If it isn't then don't worry about it, but if it is, consider making it static as well. Or even static readonly. But what am I saying here, it's your code after all and I don't know how you're using it. Do what you want
|
|
|
|
|
harold aptroot wrote: It cheated. I'm afraid I suggested an ugly work-around that is at least "bad taste".
Oh well. An explanation.
It made the "temporary" object static. That is, it is shared between all instances of the containing class (or struct). It shouldn't be (shared, that is), but it works.. But it also has the unfortunate side effect that a reference to that array is kept - forever (well, at least for a long time).
I was partially under the impression that this initialization code was for a local variable, if that were true there would be no need of such ugly hacks.
And I should have suggested something better, which I did later.. Initializing that field in the constructor.
Now, I just realized something. Code like that should almost never initialize a non-static field. Because it looks like that (jagged) array is meant to be a look-up table. If it isn't then don't worry about it, but if it is, consider making it static as well. Or even static readonly. But what am I saying here, it's your code after all and I don't know how you're using it. Do what you want Smile
I see what you mean now. The thing is I am using the jagged array as an LUT. I tried to make it static but it didn't initialize properly. I looked into the Dictionary data structure and figured out that it won't work for me. I guess I have to deal with this flaw for now. Thanks Harold for your support with this issue.
|
|
|
|
|
Hi,
if you have a non-static solution that works, and everything is read-only anyway, then you can modify it to all-static; the initialization code should go either in the normal constructor (just test whether the static stuff is still null, and initialize if it is) or start using a "static constructor".
That will save a lot of bytes and cycles, depending on the size of the jagged array and the number of class instances.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Sunday, June 12, 2011 8:19 AM
|
|
|
|
|
Hi all
My problem that i have is that i have written code to do
word rapping on a string to fit on a print document
My print document has a margin bound of a hundred(100)
Basically i have a
627 line with and
969 page height
and printing with Ariel 10pt.
My Word wrapping code wraps on a space or a \n
and I'm sitting with the problem that the rich text box does
not do the same wrapping
my rich text box font has also been set to Ariel 10pt.
one thing that if have noticed that it looks like the is a font issue
Any Help Would be greatly appreciated
Ps. have searched for something similar but with no luck
|
|
|
|
|
The only way to achieve what you want is to do the string calculation for the printer and try to calculate what the size of the RichTextBox should be to get the same effect.
The RTB is NOT a WYSIWYG control...
|
|
|
|
|
Hi all,
Can anyone tell me that how can i fire drop event of richtext box in .net2.0?I mean in my application i need to drag some data from list box and drop into rich text box.
Thanks in advance
Lijo
|
|
|
|
|
To allow drop in the RichTextBox, you have to set RichTextBox's AllowDrop property to true. Then you can handle DragEnter,DragDrop and DragOver Events.
|
|
|
|
|
Hii
everybody,
i am developing window application in c# and .net and i want to know that how to write a join query for update of local database by the content of remote server database!.
Scenario :- Suppose there is one database say softbuyweb at local machine and other database softbuyweb1 at remote server.
now there is table in softbuyweb say product and similarly there is table in softbuyweb1 say product1
now both the table product and product1 in database softbuyweb and softbuyweb1 respectively has same column/field name, datatype and length of datatype.
now i want that in my window form i place one button say "Update" on its click event there should be query which fires and the total content of table product1 at remote server is copied and the content of table product at local machine is updated with that copied content.
i think it is little confusing and also it may be difficult to write single sql query for two different data sorce connection and it might create ambiguity because both connection are establishes in a single block of code.
now , please help me on this topic , and please response as qick as possible!
my database is in sql server 2005.
thanx in advance.
|
|
|
|
|
The easiest way would be to link the SQL Server databases together so you could use an UPDATE FROM statement(Those things are like magic)
Beyond that and using any sort of Database specific synchronization open a cursor, compare records, and update the outdated db.
Need custom software developed? I do C# development and consulting all over the United States.
If you don't ask questions the answers won't stand in your way.
Doing a job is like selecting a mule, you can't choose just the front half xor the back half so when you ask me to do a job don't expect me to do it half-assed.
|
|
|
|
|
Ennis Ray Lynch, Jr. wrote: UPDATE FROM
Ennis can you elaborate on this. Is it like the select into shortcut for creating tables?
Wondering if I have missed something all these years?
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
UPDATE customer
SET customer.firstName = remoteCustomer.firstName
FROM customer
INNER JOIN remoteCustomer ON
remoteCustomer.id = customer.Id
AND remoteCustomer.GUID <> customer.GUID;
Need custom software developed? I do C# development and consulting all over the United States.
If you don't ask questions the answers won't stand in your way.
Doing a job is like selecting a mule, you can't choose just the front half xor the back half so when you ask me to do a job don't expect me to do it half-assed.
|
|
|
|
|
Thanks Ennis
Nothing new there, just thought there might have been something quite different. Sometimes I come across something in the forums completely new in a tool I have been using for ages (eq SQL).
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
hi all
i want to access gmail programatically using c#.
i will just enter my email id & password. if the email id & password is true then the server will give me a response.
but its giving me error the remote server returned an error 403
pls help me
thanks in advance
NameValueCollection nvc = new NameValueCollection();
nvc.Add("accountType", "HOSTED_OR_GOOGLE");
nvc.Add("Email", "dllcheck@gmail.com");
nvc.Add("Passwd", "dllcheck123");
nvc.Add("service", "cl");
nvc.Add("source", "Gulp-CalGulp-1.05");
WebClient client = new WebClient();
byte[] Response = client.UploadValues("http://www.google.com/accounts/ClientLogin",nvc);
string s = Encoding.Default.GetString(Response);
MessageBox.Show(s);
// http://www.google.com/accounts/ClientLogin/accountType=HOSTED_OR_GOOGLE&Email=jondoe@gmail.com&Passwd=north23AZ&service=cl&source=Gulp-CalGulp-1.05
HttpWebRequest webreqAuthenticate = (HttpWebRequest)WebRequest.Create("http://www.google.com/accounts/ClientLogin");
webreqAuthenticate.ContentType = "application/x-www-form-urlencoded";
webreqAuthenticate.Method = "POST";
webreqAuthenticate.ContentLength = 200;
//webreqAuthenticate.Timeout = 6000;
webreqAuthenticate.AllowAutoRedirect = true;
webreqAuthenticate.MaximumAutomaticRedirections = 10;
HttpWebResponse webresAuthenticate = webreqAuthenticate.GetResponse() as HttpWebResponse;
Stream streamResponse = webresAuthenticate.GetResponseStream();
|
|
|
|
|
There are existing solutions for accessing Gmail from C#:
Click[^]
|
|
|
|
|
I am not sure this is the right place for this question but here it is:
Has anyone else had problems with the SqlCeReader.Read() ? Mine doesn't like reading type int from the database and i had to write the query like this (in order to avoid Data conversion failed. [ OLE DB status value (if known) = 2 ]):
SELECT OfficialRegNo, TransponderID FROM BasicAnimal UNION SELECT CAST(FilterObjectType AS nchar), Caption FROM Filter
so, before it was:
SELECT OfficialRegNo, TransponderID FROM BasicAnimal UNION SELECT FilterObjectType, Caption FROM Filter
Anyone knows why?
|
|
|
|
|
You have a data type problem in your database. It would appear that you're trying to put a number is a string field or some other implicit conversion. Did you change a data type somewhere??
|
|
|
|
|
Hi! The datatype in the DB is int and I am only doing a Select query. Only way I could get the Read() method to work was to typecast the int to a nChar. The problem table with an int is FilterObjectType. So I am not trying to insert anything here.
Well, no I haven't changed datatypes anywhere, only this query to the DB.
BTW, I am quering a Sql Server Ce .sdf DB in this case. Not the Express here (was a bit confused when writing prev mess).
This is the only code I have written for this so far is this:
SqlCeConnection conn = new SqlCeConnection();
conn.ConnectionString = "Data Source=todos.sdf;Persist Security Info=False";
SqlCeCommand comm = new SqlCeCommand("SELECT OfficialRegNo, TransponderID FROM BasicAnimal UNION SELECT CAST(FilterObjectType AS nchar), Caption FROM Filter", conn);
conn.Open();
SqlCeDataReader myReader = comm.ExecuteReader();
do
{
Console.WriteLine("\t{0}\t{1}", myReader.GetName(0), myReader.GetName(1));
while (myReader.Read())
Console.WriteLine("\t{0}\t{1}", myReader.GetString(0), myReader.GetString(1));
} while (myReader.NextResult());
myReader.Close();
conn.Close();
|
|
|
|
|
If officialRegNo and filterObjectType are not implicitly convertible you will get this error in all versions of SQL Server.
Need custom software developed? I do C# development and consulting all over the United States.
If you don't ask questions the answers won't stand in your way.
Doing a job is like selecting a mule, you can't choose just the front half xor the back half so when you ask me to do a job don't expect me to do it half-assed.
|
|
|
|
|
Is there a simple way of sorting a BindingList by the given object element?
A code example of the OrderBy function would be very helpful!
Thank you!
|
|
|
|
|
|
I did, it does seem like an overkill since the BindingList has an OrderBy function. I just don't know how yo use it.
|
|
|
|
|
If you want to support sorting, you have to derive your own class from BindingList. This[^] MSDN article explains why you should do that and how. Please read carefully, especially the "BindingList<t>: What's Missing" section.
|
|
|
|
|
riddick_86 wrote: Please read carefully
Well that's an extremely high expectation round here. Reading carefully is also considered overkill by most our members. Magic is preferred, or when not available a copy paste solution will do.
|
|
|
|