|
1 - can't be done. Instead, make an array and put that ending digit as the index into the array
2 - can't be done.
Your overall issue is that you have something like this:
Uri uri
for(whateveR)
{
Uri uri;
}
The second Uri can't have the same name as one in the higher scope. Just use a different name, it doesn't need to be different on each iteration, it just needs to be different than the name of the variable it would otherwise hide. Or, just use the same one, if the value does not matter in the higher scope.
string s = "one";
for(whateveR)
{
s = "two";
}
// now s == "two"
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Thanks Christian. Great explanation. Now let me go and try to apply it.
Jogannon
|
|
|
|
|
Christian,
I am sorry to be so thick, however I understand the underlying need to have unique variable names. It is a matter of how does s == "two"? I do not see any counting or incrementing code in your example. My own approach (which fails) is to try and append (or concatenate an incrementing int value to the string name. Should I avoid this approach and go with a string array technique instead. Any concrete example will really help at this point.
Thanks,
Jogannon
|
|
|
|
|
"one" and "two" were arbitrary examples - the point was simply that the value given to the variable inside the second scope, applied to the first scope, too. I was illustrating that in your instance, you have a variable named uri in the outer scope, and so you couldn't create one with the same name in the inner scope, and if you reused the outer scope one to keep the same name, you would find that setting it, changed it for the outer scope.
Wow, now I'm confused
I was showing that if you used uri where you were putting Uri uri and getting the error, you would have flow on effects.
If you need to keep the variables you wanted to name uri1, uri2, etc for any reason, a list or array is the way to do that. If you were creating a variable for loop processing that is not reused, then just use a different name, like uriLoop or something.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Thanks again, Christian. Let me go and work on this.
Jogannon
|
|
|
|
|
Member 2789142 wrote: it seems to be a special URI-specific case to be part of this line
no, its not uri specific. you try to declare the variable named "uri" multiple times, which is not allowed in this case.
int myInt = 0;
foreach (object obj in objList)
{
int myInt = 4;
}
|
|
|
|
|
I need to indicate that WinForms DataGridView column in sorted.
If column width is too small, sort glyph is not displayed.
Is it possible to force sorth glyph to display in narrow columns also or any other idea how to indicate that column is sorted?
I tried also to underline column caption in mouseclick event but this fails also.
I tried
foreach (DataGridViewColumn dataGridViewColumn in grid.Columns) {<br />
DataGridViewCellStyle dgvcellStyle = new DataGridViewCellStyle();<br />
System.Drawing.Font font = new System.Drawing.Font( <br />
dataGridViewColumn.HeaderCell.Style.Font,<br />
System.Drawing.FontStyle.Underline );<br />
dgvcellStyle.Font = font;<br />
dataGridViewColumn.HeaderCell.Style = dgvcellStyle;<br />
}
But got exception probably since debugger shows that
dataGridViewColumn.HeaderCell.Style.Font
is null.
dataGridViewColumn.HeaderCell.Style is not null.
How to fix ?
Andrus
|
|
|
|
|
Hello Forum
I am now getting familiar with LINQ and in need of some help,
I have I Products table with 20 columns but I want to query only 2 columns, the simple way of querying the data
List<Product> ItemList = (from items in dataContext.Products
select items).ToList();
The issue I have is with this example, I am getting back much more data that I really need which is creates extra network traffic etc.
How can I crate a list that will implement only 2 columns of the Product class and the LINQ statement will look something like this
List<Product> ItemList = (from items in dataContext.Products
select new { items.Item_Code, items.Item_Name }).ToList();
|
|
|
|
|
Please don't cross post in multiple forums. It generally won't help you get an answer any quicker. The original post is here[^].
Scott.
—In just two days, tomorrow will be yesterday.
—Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
[ Forum Guidelines] [ Articles] [ Blog]
|
|
|
|
|
Correct,
I placed the first post not in the correct forum
|
|
|
|
|
belzer wrote: I placed the first post not in the correct forum
No problem. It is OK to delete a post in this situation, unless there are replies to it. In any case, if you realized it wasn't in the correct forum a link pointing to the correctly placed question is always useful.
Scott.
—In just two days, tomorrow will be yesterday.
—Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
[ Forum Guidelines] [ Articles] [ Blog]
|
|
|
|
|
So is this LINQ to SQL or objects? It sounds like dataContext.Products is a custom object in your data access layer. Have you tried to compile your second example? You may need to do something like this:
var ItemList = (from items in dataContext.Products
select new { items.Item_Code, items.Item_Name });
foreach(var x in ItemList)
{
Console.WriteLine("{0} - {1} ", x.Item_Code, x.Item_Name);
}
Scott.
—In just two days, tomorrow will be yesterday.
—Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
[ Forum Guidelines] [ Articles] [ Blog]
|
|
|
|
|
What i ended up doing is the following
var ItemList = (from items in dataContext.Products
select new { items.Item_Code, items.Item_Name }).ToList();
thanks.
|
|
|
|
|
Sounds like that is working for you then...this looks like what I suggested in my last reply (minus the foreach loop, which was there simply as testing).
Scott.
—In just two days, tomorrow will be yesterday.
—Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
[ Forum Guidelines] [ Articles] [ Blog]
|
|
|
|
|
Hi all,
I need to perfome simple-looking task in C#: Converting byte array to short array - meaning that if my byte array has 100 cells, my short array will have 50 cells.
If it was C/C++ it was simple, using pointers. However in C# I just can't do it - I've already tried using 'unsafe' block and memory pinning using GCHandle, with no success.
Another thing that bothers me in the solutions I found is that the conversion is done using memory copying, which is not necessary, since all the information is already there!
I'll be grateful for any solution!
Thanks,
Eyal.
|
|
|
|
|
this might work
private void foo()
{
byte[] b = new byte[100];
IntPtr hnd = Marshal.AllocHGlobal(Marshal.SizeOf(b));
Marshal.Copy(b,0,hnd,b.Length);
short[] s = new short[50];
Marshal.Copy(hnd,s,0,s.Length);
Marshal.FreeHGlobal(hnd);
}
|
|
|
|
|
Hi,
When using the code you suggested I get the following error:
Type 'System.Byte[]' cannot be marshaled as an unmanaged structure; no meaningful size or offset can be computed.
Eyal.
|
|
|
|
|
oops.. sorry.. use b.Length instead of Marshal.SizeOf(b) that should do the trick
|
|
|
|
|
Hi,
just wanted to say thanks - this works! the only problem I still have with this solution is that what it does is copying the entire byte[] memory to another location in the memory - what appears to be redundant, since it's already there! in C/C++ all I had to do is one pointer manipulation - can't I do it here as well? is it because the existance of garbage collector?
Thanks!
Eyal.
|
|
|
|
|
Hi
I think it has something to do with the Memory Management in .Net (which includes the garbage collector). As far as i understand it, object are not located fix in Memory. this means an Array of byte can "move" inside the memory.
That's why you get an exception when you try to get the Memory Address of an Item of the Array.
but you can force .Net to keep an Array at the same Location for a limited time. for this there's the fixed br mode="hold" />i'm not quite sure about this, but i think fixing is only for reading addresses.. so i don't think it's possible to set the first entry of a short array to the address of the first item of a Byte Array.
but maybe google knows more if you ask it about fixed unsafe array manipulation or something
greets
m@u
|
|
|
|
|
Is there library like ncurses for preparing command line/text terminal applications in C#?
|
|
|
|
|
Hello,
I have a form with 10 button. I want to have one click event for all these buttons. However, until vb when you can have the handles, C# doesn't seem to have it.
VB: Private Sub NumberButtonClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn0.Click, btn1.Click, btn2.Click, btn3.Click,
So when I click on button 0, 1, 2 etc I would like it to go into the event below.
Want is the method to do this in C#,
Many thanks,
Steve
private void NumberButton_Click(object sender, System.EventArgs e)<br />
{<br />
txtDisplay =+ ((Button)sender).Text<br />
}
|
|
|
|
|
hi
you could try this:
NumberButton1.Click += new EventHandler(NumberButton_Click);
NumberButton2.Click += new EventHandler(NumberButton_Click);
NumberButton3.Click += new EventHandler(NumberButton_Click);
NumberButton4.Click += new EventHandler(NumberButton_Click);
NumberButton5.Click += new EventHandler(NumberButton_Click);
NumberButton6.Click += new EventHandler(NumberButton_Click);
or:
EventHandler hnd = new EventHandler(NumberButton_Click);
NumberButton1.Click += hnd;
NumberButton2.Click += hnd;
NumberButton3.Click += hnd;
NumberButton4.Click += hnd;
NumberButton5.Click += hnd;
NumberButton6.Click += hnd;
greets
m@u
|
|
|
|
|
Hi,
I`ve spent a lot of time looking for a solution for my problem.
I believe I find it here.
My problem is:
I`m developing an application in C# that in fact is a webbrowser with a small extension.
That extension applies to what happens when I resize the window of the webbrowser or
change resolution of my screen.
When I resize webbrowser`s window (ordinary webbrowsers), some objects
on the current page are invisible and I have to scroll horizontaly to see it again.
My webbrowser have to move these objects so they will be visible without need of horizontal scrolling(only vertical).
Is there some way of how to locate and remove these objects? Or the only way is to change their style.
I`ll be thankful for any ideas.
|
|
|
|
|
eswes wrote: Or the only way is to change their style.
If you are talking about CSS and positioning the HTML elements then yes. There is no way to override the browsers rendering of the elements.
If that's not what you are asking then I have no idea what it is.
led mike
|
|
|
|