|
I'm assuming by stack you mean the stack that the program stores it's local variables in (not one you've produced yourself using the Stack class.
When the variables are stored, the stack is just a way of looking at the specific area of memory. Unlike the .Net Stack class, you don't have to pop things off to access them. The same region of memory could also be treated as a list, a queue, or anything else. The program stores the address of each variable, and then accesses them directly, so you can access b without touching c . Then, when the function finishes, all the variables are popped off of the stack.
This is one of several ways of storing local variables in a function, and is very low level stuff. You shouldn't have to worry too much about it.
Disclaimer: The .Net Framework may do something different to the stack, but the principle should be the same.
|
|
|
|
|
Thanks for the replies, yes I was talking about local variables, and not the Stack class. Yes, I agree that I don't want to worry too much about low-level memory management.
The confusion came about because of all the images on the internet that show the stack as a bunch of boxes on top of each other. Someone asked me that question, and I suddenly realized I couldn't give them an answer!
Thanks again,
--Alex
|
|
|
|
|
Hi,
the stack is a region in memory pointed to by a special register, the stack pointer.
It is special in the sense that some assembly instructions implicitly use the stack pointer:
CALL/JSR push the current PC on the stack
RETURN/RTS pop the old PC value from stack and store it in the PC register
PUSH pops anything onto the stack
POP pops anything from the stack
On top of that, the stack pointer can be used as a regular base register, so indexed addressing is supported. Local variables, while stored on the stack are accessed with an offset (or "displacement") so there is no pushing/popping involved.
Summary: the stack works as a regular stack (implied pushes and pops) when program flow alters (CALL, RETURN); it is used as a memory region (with base address+offset) when local variables are accessed.
All the above is valid at two different levels:
- assembly instructions (as in native code applications);
- .NET environment with IL instructions (managed code).
|
|
|
|
|
I'm having a problem in sorting strings. All the strings are saved in a text file. Now i retrieved the strings from the text file and transferred it into an array. I'll be using radix sort to sort the strings because I think its the most appropriate algorithm to use beside any other sorting algorithm. But first I want to convert all the strings into their corresponding ASCII codes and store all the ASCII codes into a temporary array so I can sort them in a much better way.
Now my problem is always get the FormatException during run-time. How will I solve that error? I already declared an array that's an int type but i still get that error.
using (StreamReader outputLastNames = new StreamReader("lastnames.txt"))
{
for (int i = 0; i < vehicleCountInt; i++)
{
arrayOfLastNames[i] = outputLastNames.ReadLine();
convertedLastName[i] = Int32.Parse(arrayOfLastNames[i]);
}
}
important notes:
convertedLastName[i] is an int[] type
arrayOfLastNames[i] is a string[] type
modified on Tuesday, September 1, 2009 2:42 PM
|
|
|
|
|
OK, I don't get why you want to convert to ASCII, but never mind. What do you get the FormatException on? If you don't show us the code that gives the problem, it is next to impossible to help. Don't paste the lot, just the relevant fragment, and don't forget to enclose it in <pre></pre> markers to preserve the formatting (makes it easier for us to read).
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
How do expect to parse a (person's?) name to an int?
If your last name is 1127 it would work; but not with most names.
|
|
|
|
|
Just a guess, but are you sure all of the characters in the name can be converted to int?
only two letters away from being an asset
|
|
|
|
|
How can a character in a name be converted to an int?
Anyway - this will handle it using the TryParse method, though I suspect you're going to spend most of your time in the else block.
int converted;
if(Int32.TryParse(arrayOfLastNames[i], out converted)
{
convertedLastName[i] = converted;
}
else
{
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Int32.Parse would work with char and not strings. i.e. (char)'A' will be converted to its ASCII equivalent but (string)"A" will not. You will need to get each character of the last name and then convert.
AFAIK .Net uses UTF8 encoding to store strings, probably that is the reason it is not working now.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
Uggh...What was I thinking?! My fault guys..wrong question..I was thinking about the type of an ASCII code.
So, is there a way to convert all the string into an ASCII code? I was thinking of converting all of the string to ASCII code because I think it's a good way to do to sort using radix sort just like what i said above.
modified on Tuesday, September 1, 2009 3:40 PM
|
|
|
|
|
1. Why can't you use Array.Sort method?
2. AFAIK the number of recursions depend upon the maximum number digits in the numbers. Hence, if you have last names like MacGhilleseatheanaich[^], I wonder how many iterations it would take.
To convert string to ASCII equivalent, you can use following code:
System.Text.Encoding encASCII= System.Text.Encoding.ASCII;
Byte[] stringBytes = encASCII.GetBytes(yourString);
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
The reason why i can't use Array.Sort() is because we're trying to implement all that we discussed about file organization and data structure etc, and because we discussed some sorting algorithms we'll be implementing radix sort. If we were not obliged to use radix sort, I would be eager to use Array.Sort and finish the program easily. 
|
|
|
|
|
They're already in ASCII.
But if you want to waste bits by using int (32 bits) rather that char (16 bit), you can cast the chars to ints.
foreach ( char ch in s )
{
int i = (int) ch ;
...
}
|
|
|
|
|
Hi Everyone,
I have a "one to many" sort of situation. I am using a Key to get subset data. I started out using a class like this:
<code>
public class Contract
{
public int ContractID {get;set;}
public int CustomerID {get;set;}
public string CustomerName {get;set;}
public string Organization {get;set;}
public int TermsID {get;}
}
public class ContractDataMapper
{
public static List<Contract> GetContractData(int contractID)
{
List<Contract> returnValue = new List<Contract>();
...
while(reader.Read())
{
Contract contract = new Contract();
contract.CustomerID = Convert.ToInt32(reader["CustomerID"]);
contract.CustomerName = reader["CustomerName"].ToString();
...
if(!returnValue.Contains(contract))
returnValue.Add(contract);
}
reader.Close();
command.Dispose();
return returnValue();
}
}
</code>
But I soon realized that this is bad because I had to check to see if this ContractID has any TermsID associated with it and the way it currently is I would have to do something like:
if(ContractDataMapper.GetContractData(1234)[0].TermsID > 0)
Ideally I should have one class Contract and have other properties in a subclass. Now my question is ... do you think it would be better to have a struct or a subclass or something else?
Contract contract = new Contract(1234);
List<SubsetData> subset = contract.SubsetData;
I would appreciate your help.
|
|
|
|
|
|
using Automation (SHDocVw, MSHTML or something else?) or a WebBrowser control:
1)Is it possible to interrogate a flash control to discover its elements? For example, http://demo.garanti.com.tr/bireysel_demo/main.html[^], there are flash buttons. Can I determine there "ID"s?
2)Given the "ID" names of elements in a flash control, is it possible to click and/or select them?
|
|
|
|
|
New to C# - long time cobol programmer....
How do you define a db connection so it can be used across several windows forms?
I have the connection working but I have to establish the connection in each form.
iDB2Connection cn = new iDB2Connection();
cn.ConnectionString = "DataSource=" + txtiSeries.Text.Trim(' ')
+ ";DefaultCollection=" + txtDataLibrary.Text.Trim(' ')
+ "; UserID=" + txtUserId.Text.Trim(' ')
+ "; Password=" + txtPwd.Text.Trim(' ') + ";LibraryList=*USRLIBL;";
try
{
cn.Open();
}
catch (iDB2CommErrorException x)
I would like to be able to establish the connection 1 time when the application starts and then be able to use it
across all of the windows forms.
Just not sure were or how to define it.
Any help would be appreciated.
Thanks
|
|
|
|
|
It would be a bad idea to keep the database connection open constantly, It is much better to create a connection each time you need one.
I tend to use a class that does all my database work, which includes creating a connection when needed. This class provides functions for specifying search criteria. You could consider a simple class that simply takes an SQL query string and returns a datatable of the results (for search functionality) - In this case database connection string could be a static member of the class which is set when the application first loads.
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Create a data class that handles all data calls to & from the data source. I have one if you need it.
Then in your main class, mine is called csApp, create a class variable that holds it:
public static DataClass DataAccess;
Next, in the Main method do:
public static void Main(String[] args)
{
DataAccess = new DataClass();
}
Then, anytime you need to call into the data source you can do:
DataSet ds = csApp.DataAccess.GetDataSet("select * from ....")
This way it's always available. And you should always close the connection when you're
not using it.
Everything makes sense in someone's mind
|
|
|
|
|
Hi
You can an app.config file to your project and write this code into it
<configuration>
<appsettings>
<add key="Accesskey" value="Data source=;Initial catalog=;user id=;Password=">
if you have done this write this code your destination form where you have to make connection.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsApplication9
{
public partial class Form1 : Form
{
SqlConnection connection;
string con;
public Form1()
{
con = System.Configuration.ConfigurationSettings.AppSettings["Accesskey"].ToString();
connection = new SqlConnection(con);
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
connection.Open();
}
}
}
Here this code writern in C# language you have to just convert it into VB.NET.
|
|
|
|
|
hi
?xml version="1.0" encoding="utf-8" ?
<configuration>
<appSettings>
<add key="Accesskey" value="Data source=.;Initial catalog=kirti;user id=sa;Password=./>
</appSettings>
</configuration>
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsApplication9
{
public partial class Form1 : Form
{
SqlConnection connection;
string con;
public Form1()
{
con = System.Configuration.ConfigurationSettings.AppSettings["Accesskey"].ToString();
connection = new SqlConnection(con);
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
try
{
connection.Open();
SqlCommand commad = new SqlCommand("select *from " + textBox1.Text.ToString() + "", connection);
SqlDataAdapter ad = new SqlDataAdapter(commad);
DataSet ds = new DataSet();
ad.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
finally
{
connection.Close();
}
}
}
}
This code is writren in C# you have just convert into VB.NET.
|
|
|
|
|
Hi all,
Can some one tell me how can I get a list of different DBMS/ Database server, those are installed in a computer using C#.
|
|
|
|
|
For SqlServer only:
private void GetServerList()
{
DataTable dt;
dt = SmoApplication.EnumAvailableSqlServers(false);
if (dt.Rows.Count > 0)
{
foreach (DataRow dr in dt.Rows)
{
ServerNamesComboBox.Items.Add(dr["Name"]);
}
ServerNamesComboBox.SelectedIndex
= ServerNamesComboBox.FindStringExact(
System.Environment.MachineName);
if (ServerNamesComboBox.SelectedIndex < 0)
{
ServerNamesComboBox.SelectedIndex = 0;
}
}
else
{
ExceptionMessageBox emb = new ExceptionMessageBox();
emb.Text = Properties.Resources.NoSqlServers;
emb.Show(this);
}
}
cannot help with non-SqlServer DBMSs.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Thanks for reply.
But I can not run this because of the following errors:
Error 2 The name 'SmoApplication' does not exist in the current context
Error 3 The type or namespace name 'ExceptionMessageBox' could not be found (are you missing a using directive or an assembly reference?)
Error 4 The type or namespace name 'ExceptionMessageBox' could not be found (are you missing a using directive or an assembly reference?)
Error 5 'WindowsApplication1.Properties.Resources' does not contain a definition for 'NoSqlServers'
|
|
|
|
|
All of the code can be run using standard .NET Framework references.
Google, or search MSDN, for smoapplication. From there you will find links to information that will help you to get it running.
As part of the process you will have to add references to the following assemblies:
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer;
using Microsoft.SqlServer.MessageBox;
The code comes from one of the SqlServer samples downloads, from MSDN.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|