|
Hi,
The difference is --
The value of const is evaluated at compile time and the value of readonly are evaluated at runtime.
Means u cannot assign value to const at runtime like this --
const int a = someVariable;
but you can do --
readonly int a = someVariable;
<marquee>"A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder
Anant Y. Kulkarni
|
|
|
|
|
Hello Anant,
Anant Y. Kulkarni wrote: const int a = someVariable;
'someVariable' or must have some constant value?
if i changed value of someVariable before upper statement then it will be runtime binding.
Isn't it?
regards,
Divyang Mithaiwala
System Engineer & Software Developer
|
|
|
|
|
Hi,
The difference is --
The value of const is evaluated at compile time and the value of readonly are evaluated at runtime.
Means u cannot assign value to const at runtime like this --
const int a = someVariable;
but you can do --
readonly int a = someVariable;
I meant that you cannot assign a variable to a const. It should be a constant like --
const int a= 50
I just wrote the opposite.
<marquee>"A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder
Anant Y. Kulkarni
|
|
|
|
|
You also keep in mind the limitations of const vs. read-only.
In the case that you have an assembly you distribute, internally or to customers, that contains CONST values. Since CONSTs are set at compile time, if you update your values and distribute the updated assembly unless the apps are recompiled with your new assembly they will still have the old vlaues for the CONST variables.
only two letters away from being an asset
|
|
|
|
|
Taken from the MSDN[^] documentation for the readonly keyword:
When a field declaration includes a readonly modifier, assignments to the fields introduced by the declaration can only occur as part of the declaration or in a constructor in the same class.
A const field can only be initialized at the declaration of the field. A readonly field can be initialized either at the declaration or in a constructor. Therefore, readonly fields can have different values depending on the constructor used. Also, while a const field is a compile-time constant, the readonly field can be used for runtime constants.
|
|
|
|
|
How will you create a 64–bit application using Visual Studio .NET 2003?
|
|
|
|
|
Set the Platform Target in the project properties to x64
only two letters away from being an asset
|
|
|
|
|
That'll work for C# in Visual Studio.NET 2005, but not in VS.NET 2003.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hi All
How I can Use Thread with ListView To Add this Items
ListViewItem lvi = new ListViewItem(new string[] { splitString[1], splitString[2].Substring(0, 12), splitString[2].Substring(17, 12), tempstring }); <br />
this.listView1.Items.Add(lvi);
|
|
|
|
|
Hi,
You can create new object of Thread class and assign a function which will perform the above said operation for you. Remember that the function should not return any thing (ie return type = void ) and should not accept any arguments. In case if you want to pass some arguments when the thread will actually start then you can use fields or properties which would be accessible from inside the function. For example --
Thread objThread = new Thread(new ThreadStart(this.FunctionName));<br />
objThread.Start();
the FunctionName would be your function defined as below--
public void FunctionName()<br />
{<br />
ListViewItem lvi = new ListViewItem(new string[] { splitString[1], splitString[2].Substring(0, 12), splitString[2].Substring(17, 12), tempstring });<br />
this.listView1.Items.Add(lvi);<br />
}<br />
If you want now to pass any arguments to FunctionName then use fields or properties. Means before u call objThread.Start() assign the right fields with the values you want to pass to the Thread.
Hope i am clear !
<marquee>"A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder
Anant Y. Kulkarni
|
|
|
|
|
thanks Anant Y. Kulkarni
I am use this code
private void loadSubToolStripMenuItem_Click(object sender, EventArgs e)<br />
{<br />
<br />
OpenFileDialog1.Filter= "Srt File|*.srt";<br />
OpenFileDialog1.Title = "Open SubTitle File";<br />
try<br />
{<br />
if (OpenFileDialog1.ShowDialog() == DialogResult.OK)<br />
{<br />
Thread ReadThread = new Thread(new ThreadStart(ReadData));<br />
ReadThread.Start();<br />
}<br />
}<br />
catch (Exception)<br />
{<br />
MessageBox.Show("Can't Read this File");<br />
}<br />
}
and this Function
private void ReadData()<br />
{<br />
listView1.Items.Clear();<br />
StreamReader s = new StreamReader(OpenFileDialog1.FileName, Encoding.Default);<br />
ArrayList a = new ArrayList();<br />
while (s.Peek() >= 0)<br />
{<br />
string alltext = "";<br />
string text = "";<br />
while ((text = s.ReadLine()) != "" && text != null)<br />
{<br />
alltext += ("|" + text);<br />
}<br />
a.Add(alltext);<br />
}<br />
s.Close();<br />
foreach (string text in a)<br />
{<br />
string[] splitString = text.Split('|');<br />
string tempstring = "";<br />
for (int i = 3; i < splitString.Length; i++)<br />
{<br />
tempstring += splitString[i];<br />
}<br />
ListViewItem lvi = new ListViewItem(new string[] { splitString[1], splitString[2].Substring(0, 12), splitString[2].Substring(17, 12), tempstring }); <br />
this.listView1.Items.Add(lvi);<br />
}<br />
a.Clear();<br />
}
when i Run this Program this message Dispaly
Exception System.InvalidOperationException was thrown in debuggee:
Cross-thread operation not valid: Control 'listView1' accessed from a thread other than the thread it was created on
|
|
|
|
|
|
how to get single item in foreach loop ??
here is the sample
foreach (clsLabels lbl in m_clsLabelCollection)
{
lstlblname.Items.Add(lbl.label);
lstlblvalue.Items.Add(lbl.Value);
lstcustext.Items.Add(lbl.customValue);
}
i want a perticular lable from the clsLabelCollection(collection class inherited from CollectionBase) class
clsLabels constructor added to clsLabelCollectionclass
clsLabels(string,string,string)
sikandar
|
|
|
|
|
sikandarhayat wrote: i want a perticular lable
Whats different on this label?
|
|
|
|
|
actually clscollection class contain a list of labels
and i want if a perticualr label name equals"name" which is exists in the collection class.
how can i extract it.
thanks for reply
sikandar
|
|
|
|
|
Hello,
Got it now!
foreach(Label l in clscollection)
{
if(l.Name == "yourename")
{
//thats it
}
}
All the best,
Martin
-- modified at 4:17 Friday 25th August, 2006
|
|
|
|
|
hi
no not in that way
i mean is there any other way loop mean continous searching i want to save time i do not want to compare just assign of perticular.
if possible
thanks.
sikandar
|
|
|
|
|
An ArrayList (the inner list of the CollectionBase) has nothing that supports accessing items in any other way.
You can use a HashTable and use the name of the label as key, then you can access the labels directly by name.
---
b { font-weight: normal; }
|
|
|
|
|
Hi,
you can use
lbl.Name ie,
if (lbl.Name.Equals("your constant value"))
{
//your code goes here
}
property.
hope this works.
Nitin...
|
|
|
|
|
Double up the collection. Often I will use both a list and a hash in 1.1. I use the list for iteration and the hash for indexing. If the data is good enough I will keep it in an Array List sorted and Binary Search it.
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 rightly to apprehend the kind of confusion of ideas that could provoke such a question. - Charles Babbage
|
|
|
|
|
Since you mentioned that clsLabelCollection inherits from CollectionBase, it should have a Contains and an IndexOf method.
Assuming that both of these are actually implemented in the collection class, you can use them to find a specific clsLabels instance:
clsLabels l = null;
if (m_clsLabelCollection.Contains("value"))
{
int i = m_clsLabelCollection.IndexOf("value");
l = m_clsLabelCollection[i];
}
You can also iterate over the collection (using foreach) and explicitly test to see if the current item is equal to the one you want. When you find the match, break out of the loop.
This would be something like this:
clsLabels l = null;
foreach(clsLabels lbl in m_clsLabelCollection)
{
if (lbl.label == "value")
{
l = lbl;
break;
}
}
I'm assuming that lbl.label is a string field and that you are looking for the label "value".
|
|
|
|
|
Hello!
How many GraphicsState can we save. Does it depend on hardware capability? If so, how to get that stack size?
<br />
GraphicsState state1 = g.Save();<br />
GraphicsState state2 = g.Save();<br />
GraphicsState state3 = g.Save();<br />
...<br />
g.Restore(state3);<br />
g.Restore(state2);<br />
g.Restore(state1);<br /> ]
Thank you.
Sovann
|
|
|
|
|
s o v a n n wrote: If so, how to get that stack size?
I dont think you want to call that recursively, its a rather expensive operation. Performace will be terrible before you hit stack overflow.
|
|
|
|
|
Dear All,
I am showing some thumbnail pictures in a listbox. Thumbnails have category. Now I want to show tumbnails category wise in ListBOx. So that i can expand or collapse each category to see thumbnails like tree view. Have anybody some idea about it?
|
|
|
|
|
can you use a listview but listbox?
because the listview has SmallImageList property. it can show picture on a item.
|
|
|
|