|
Do you want a simple answer or all the gory details[^]?
Simple:
Rags1512 wrote: how does CLR differentiate between the two
It's in the metadata, see .NET file format - Signatures under the hood, Part 1 of 2[^]
Rags1512 wrote: stores the value type on Stack and reference types on Heap
That's very misleading, reference types end up putting something in the heap as well as on the stack and value types may well be in the heap (as a field of a reference type, for example). The (well "a") difference is that an instance of a value type can be on the stack, whereas an instance of a reference type is always in the heap (but it may have a reference to it on the stack)
Rags1512 wrote:
Question is where does the employeeCount will get stored(Stack or Heap) and Where does the cmpny gets stored?
employeeCount will be in the heap, inside the instance of the Company it is part of. Where cmpny is stored is impossible to tell without more context. If that line is part of the declaration of a reference type (field with initializer) it will be in the heap as part of it's parent object, if that like is part of the declaration of a value type it may end up on the stack (or the instance of the value type it is in could be a field of a reference type), if that line is inside a method (local variable with initializer) it will definitely be on the stack. But the instance of the Company that cmpny refers to will always be in the heap.
I think.
|
|
|
|
|
|
It was helpful. Thanks!
Praveen Raghuvanshi
Software Engineer,
India.
|
|
|
|
|
check this link again
http://opexsolution.com/forum/viewtopic.php?f=18&t=8
you will get more clear idea about Reference and Value types
|
|
|
|
|
Good day.
I am building a small application and need to pass a startdate and enddate value to a SQL Stored Procedure. I have setup a DataGrid View with the stored Procedure as the Datasource. I have also created two textboxes in the form called Stardate and EndDate resprectively.
How do I pass the values typed into the textboxes to the SQL Query? I have thought of using a button to execute the query.
|
|
|
|
|
Pass the values to parameters of the stored procedure using code similar to the following:
con = new SqlConnection("server=xxx;database=xxx;uid=xxx;pwd=xxx");
cmd.Parameters.Add("@StartDate", SqlDbType.DateTime).Value = StartDate.Text;
cmd.Parameters.Add("@EndDate", SqlDbType.DateTime).Value = EndDate.Text;
cmd = new SqlCommand("insert_with_sproc", con);
cmd.CommandType = CommandType.StoredProcedure;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
I'll leave data validation and any exception handling to you but that, essentially, is what you can do. There are, of course, many other ways to do this and you should select the method most appropriate to your needs.
me, me, me
"The dinosaurs became extinct because they didn't have a space program. And if we become extinct because we don't have a space program, it'll serve us right!"
Larry Niven
|
|
|
|
|
how can i edit,remove and add a node on a treeview in the runtime?
|
|
|
|
|
the following code snippet generate classes nodes has a childe nodes "Semester"
private void FillTreeNodes()
{
SysClass sysclass = new SysClass();
DataSet ds= sysclass.GetAllSysClasss();
TreeNode node;
foreach (DataRow row in ds.Tables[0].Rows)
{
node = new TreeNode();
node.Text = row["Class"].ToString();
node.Value = row["ClassId"].ToString();
node.NavigateUrl = "UpdateClass.aspx?classId="+node.Value;
GenerateSemesters(node,int.Parse(row["ClassId"].ToString()));
tree1.Nodes.Add(node);
}
}
private void GenerateSemesters(TreeNode node,int classid)
{
Semester semester=new Semester();
DataSet ds = semester.GetAllSemesters(classid);
TreeNode childenode;
foreach (DataRow row in ds.Tables[0].Rows)
{
childenode = new TreeNode();
childenode.Text = row["SemesterName"].ToString();
childenode.Value = row["SemesterId"].ToString();
childenode.NavigateUrl = "Updatesemester.aspx?semesterId=" + childenode.Value;
node.ChildNodes.Add(childenode);
}
}
i forget to minsion that is the best way for filling treeview is recursively !
modified on Monday, March 29, 2010 4:46 AM
|
|
|
|
|
|
Hi every one.
I'm working with MS Access2007-2010.As you know MS Access is too weak to make good program with it.For some reason i'm forced to work with MS Access.But it's too limited and i can't do what ever i want like C#.
I want to know is there any way to write c# code and use it in MS Access?
And use c# components in Access?
And imagin i have access form with some textBoxs,How can make the data encrypted and save it in Access dataBase?(From Access Forms,like the thing we do in C# Forms).
Thank you.
CanI
|
|
|
|
|
As far as I am aware you are stuck with the Access variant of VBA for your programming needs.
However, you should be able to create a dll (in c# or c++) and use that in the code (You'll have to look that bit up: it has been a lot of years since I used Access).
Roya Rayane wrote: MS Access is too weak to make good program with
That's really going to depend upon the requirement. If it's for an enterprise type solution then yes, you should be looking at something more robust like ORacle or SQl Server. However, for small, departmental requirements where there are few users, it might be just fine.
me, me, me
"The dinosaurs became extinct because they didn't have a space program. And if we become extinct because we don't have a space program, it'll serve us right!"
Larry Niven
|
|
|
|
|
You can write components in C#, exposing them through COM, which can be used in Access VBA. You cannot write C# code directly in Access and expect it to work.
|
|
|
|
|
How can i have something like this :
int i=0;
if(i>0)
List<string> Age = new List<string>();
else if(i==0)
List<int> Age = new List<int>();
string strAge = Age.ToString();
it gives this Error :
Error : The name 'Age' does not exist in the current context
Please give me a Solution.
modified on Monday, March 29, 2010 2:01 AM
|
|
|
|
|
Use like this.Age is not in if block thats why it not found.
List Age;
int i=0;
if(i>0)
Age = new List();
else if(i=0)
Age = new List();
string strAge = Age.ToString();
|
|
|
|
|
ummm ... isnt that the same as:
List Age = new List();
string strAge = Age.ToString();
because I is always going to be 0 in this case. Also if its not 0 it does the same thing as if it is 0 so ...
Brad Barnhill
|
|
|
|
|
How can i have something like this :
int i=0;
if(i>0)
List<string> Age = new List<string>();
else if(i==0)
List<int> Age = new List<int>();
string strAge = Age.ToString();
it gives this Error :
Error : The name 'Age' does not exist in the current context
Please give me a Solution.
|
|
|
|
|
You are attempting to create the List<>Age in the if statements and then working with Age outside the if statements, VS gets does not know if Age actually exists.
What if i = -1, neither of your ifs will create Age and it would be null so vs spits the dummy and makes you clean up your code. And as you are trying to make the list different formats then you are in trouble, if there is going to be characters in your Age then just use List<string> and test the values for numerics in the consuming process.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
|
I knew that But i want to do something like my question ?
|
|
|
|
|
As a rule, you cannot create an instance in single line if block.
so,
jojoba2011 wrote: if(i>0) List<string> Age = new List<string>();
is illegal.
Now, to be able to do this, you need to cover them in curly brackets. which means that the list you created doesn't exist outside the if block and hence the error.
|
|
|
|
|
string strAge;
int i=0;
if (i > 0)
{
List<string> Age = new List<string>();
strAge = Age.ToString();
}
else if (i == 0)
{
List<int> Age = new List<int>();
strAge = Age.ToString();
}
Check if this works.
Tej Aj,
http://opexsolution.com/forum/[^]
|
|
|
|
|
1. The above code still does not compile: you must give value strAge before the if blocks.
2. I think the OP might want something more than just the type name of the list.
|
|
|
|
|
string strAge = "";
int i = 0;
if (i > 0)
{
List<string> Age = new List<string>();
strAge = Age.ToString();
}
else if (i == 0)
{
List<int> Age = new List<int>();
strAge = Age.ToString();
}
I have checked this. It works fine. Try checking it again by initializing strAge="" at the start.
Also strAge is already declared before if block.
Tej Aj,
http://opexsolution.com/forum/[^]
|
|
|
|
|
Is there any issue if you use a List<object> for doing this?
int i=0;
List<object> Age = new List<object>();
string strAge = Age.ToString();
WWW, WCF, WWF, WPF, WFC .... WTF
|
|
|
|
|
That's kind of pointless. You've created a generic of type object which is the same as just having a none-generic List. What you are doing here is requiring that both types need to be boxed/unboxed which is an expensive operation - this is precisely the type of thing that generics were introduced to avoid.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|