|
Arrays are not resizable. So if you have space available in current array, you can assign data to that location. Else you need to copy the whole array contents to a new array with more storage location. Array class has methods to make this easier.
|
|
|
|
|
|
Precisely.
[edit]
I re-read your post. An Array is a fixed, contiguous series of identical data-types that have been reserved in memory and can be directly accessed through an address offset (eg. X[0] or X[6]). Arrays are static in size, you cannot append to them, you can most certainly change their contents.
A String is an array of characters, therefore, the same applies.
OTOH, dynamic data structures such as lists, queues and stacks can change in size and have items appended and removed.
|
|
|
|
|
Thanks Mustafa,
Mustafa Ismail Mustafa wrote: A String is an array of characters, therefore, the same applies.
Not quite agree with above statement. I think for array, we can not change its content (e.g. when change some specific char inside a string, a new instance will be created), correct?
regards,
George
|
|
|
|
|
George_George wrote: I think for array, we can not change its content
We can change it's content.
int[] a = new int[]{10,20,30};
a[1] = 40;
George_George wrote: when change some specific char inside a string, a new instance will be created
You can't do the same with strings as you did for arrays.
string str = "hello";
str[0] = 'a';
|
|
|
|
|
Cool, N a v a n e e t h!
regards,
George
|
|
|
|
|
Mustafa Ismail Mustafa wrote: A String is an array of characters, therefore, the same applies.
I doubt this. Array is a block of data with some length and provides indexer to access the data. This is correct for strings. But AFAIK, strings are stored as inline not as character array. Correct me if I am wrong.
Mustafa Ismail Mustafa wrote: lists, queues and stacks can change in size
MS just wrapped the array copying logic inside these classes. When additional space required, a new array will be created and existing contents will be copied to there.
|
|
|
|
|
Thanks N a v a n e e t h!
1.
What is the differences between "stored as inline" type of data structure and "character array" type of data structure?
2.
N a v a n e e t h wrote: MS just wrapped the array copying logic inside these classes.
Queue, stack and list are implemented as array internally -- means continuous linear storage?
regards,
George
|
|
|
|
|
1 - String data is stored directly in the string object. Just examine the heap, you can understand this.
2 - Yes. Queue, Stack uses arrays internally.
|
|
|
|
|
Thanks N a v a n e e t h,
1.
Good to learn List/Stack/Queue are using continious linear storage other than using C style pointed based linked list.
2.
What means "directly in the string object"? You mean not storing a pointer or reference (by some level of indirection)?
3.
N a v a n e e t h wrote: examine the heap
You mean watch the managed heap address? The same address for the string variable and the string content?
regards,
George
|
|
|
|
|
N a v a n e e t h wrote: I doubt this. Array is a block of data with some length and provides indexer to access the data. This is correct for strings. But AFAIK, strings are stored as inline not as character array. Correct me if I am wrong.
A string is a sequential collection of Unicode characters that is used to represent text. A String object is a sequential collection of System.Char objects that represent a string. The value of the String object is the content of the sequential collection, and that value is immutable.
A String object is called immutable (read-only) because its value cannot be modified once it has been created. Methods that appear to modify a String object actually return a new String object that contains the modification. If it is necessary to modify the actual contents of a string-like object, use the System.Text.StringBuilder class. (source: http://msdn.microsoft.com/en-us/library/system.string.aspx[^])
An Array by definition is a sequential collection of the same data type accessed through an indexer (offset). So it seems like it. Also, It appears that (specifically with strings) even if you try to alter the contents, a new string is actually returned.
N a v a n e e t h wrote: MS just wrapped the array copying logic inside these classes. When additional space required, a new array will be created and existing contents will be copied to there.
I can't find any sources for or against this argument, but from what I know and remember, all these collection objects are based on the original ArrayList which inherits directly from the System.Object, whilst all the other ValueTypes inherit from System.ValueType, so I'd guess they're different. Also, aren't arrays pushed onto the stack whilst the other dynamic datastructures get pushed onto the heap? I'm not too sure, so don't consider my arguments as final. Indeed, this is becoming something I'm interested in finding out.
|
|
|
|
|
Mustafa Ismail Mustafa wrote: Also, aren't arrays pushed onto the stack whilst the other dynamic datastructures get pushed onto the heap?
Arrays are reference types. So goes to heap not stack. Check this[^]
Mustafa Ismail Mustafa wrote: I can't find any sources for or against this argument,
Look into List<T> class using reflector. You will come to know.
|
|
|
|
|
Excellent. Thank you indeed, it was a pleasure learning all of this
Kudos Navaneeth.
|
|
|
|
|
I am delighted. Thanks Mustafa.
|
|
|
|
|
Where ever you have read it its correct that strings are immutable and a new instance is created.
And when you append add or do any other operation a new instance is created so always be precise with your string operations.
Ahsan Ullah
Senior Software Engineer
|
|
|
|
|
|
Good day. I would like to create a C# program that run full screen with looped video (avi/mpeg) as background.
Can anyone give me some hints on how to start as I have no idea which MSDN functions I should use?
Thank you.
|
|
|
|
|
Can anyone give me some hints on how to start as I have no idea which MSDN functions I should use
You must know that MSDN is not a framework whose functions you want to know. And if you want piece of code then you wont get it here. Try google, you will find many articles on it.
For full screen set the mode of form to full screen.
Ahsan Ullah
Senior Software Engineer
|
|
|
|
|
Geez, ease up. He never said MSDN was a framework--he was talking about finding functions on MSDN, of which there are a million. Also, MSDN has lots of code samples, so I don't know what you're talking about.
Edit: My bad, re: code you said "here"; I read "there".
“Time and space can be a bitch.”
–Gushie, Quantum Leap
{o,o}.oO( Looking for a great RSS reader? Try FeedBeast! )
|)””’) Built with home-grown CodeProject components!
-”-”-
|
|
|
|
|
As it has been already said, try to google out for the code...
And if you dont know how to google it...This[^] is an example...
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
Thank you for reply. But I still unmanage to find a method to play video (avi) on the background of window form... Anyone have solution?
|
|
|
|
|
you will need some player component (for eg. Media Player) to do this
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
I had to buid the programs but when i run it which had to occupy butffer. So that i need to help to resolve this problem.
Evething idea please send fllowing Address mail: medop82@yahoo.com
Thanks you very much!
the class of me
public class CatalogueArea
{
#region Define
private System.Data.SqlClient.SqlConnection con = Medop.Define.Global.Static.ClassStatic.con;
private string[] _ArrayReturn = new string[] { Medop.Define.Global.Static.ClassStatic.DefaultEmpty, Medop.Define.Global.Static.ClassStatic.DefaultEmpty, Medop.Define.Global.Static.ClassStatic.DefaultEmpty };
private System.Data.DataSet _DsNull = null;
private string _CodeReturn;
#endregion Define
#region Contruct
public CatalogueArea()
{
}
#endregion Contruct
#region Public
public int VoidCheckExit(string input, string NameFile, string NameTable)
{
try
{
string sql;
if (con.State != ConnectionState.Open) con.Open();
sql = "SELECT * from " + NameTable + " where 1=1 and " + NameFile + "=" + "'" + input + "' ";
SqlCommand cm = new SqlCommand();
SqlDataAdapter da = new SqlDataAdapter();
DataSet mDataset = new DataSet();
cm = new SqlCommand(sql, con);
cm.ExecuteNonQuery();
da = new SqlDataAdapter(sql, con);
da.Fill(mDataset, Define.Global.Static.ClassStatic.NameTable);
da.Dispose();this.con.Close();
if (mDataset.Tables[Medop.Define.Global.Static.ClassStatic.NameTable].Rows.Count != 0)
return 0;
else
return 1;
}
catch
{
return 10;
}
}
public DataSet VoidGetNoneDataset()
{
try
{
string sql;
if (con.State != ConnectionState.Open) con.Open();
sql = "SELECT 0 AS STT, CODE_AREA, NAME_AREA, NOTE FROM dbo.AREA WHERE (1 <>1)";
SqlCommand cm = new SqlCommand();
SqlDataAdapter da = new SqlDataAdapter();
DataSet mDataset = new DataSet();
cm = new SqlCommand(sql, con);
cm.ExecuteNonQuery();
da = new SqlDataAdapter(sql, con);
da.Fill(mDataset, Define.Global.Static.ClassStatic.NameTable);
da.Dispose();this.con.Close();
return mDataset;
}
catch
{
return _DsNull;
}
}
public int VoidInsert(string CODE_AREA, string NAME_AREA, string NOTE)
{
try
{
if (VoidGetDataset(CODE_AREA, true).Tables[Medop.Define.Global.Static.ClassStatic.NameTable].Rows.Count != 0)
{
return 0;
}
string sql = Medop.Define.Global.Static.ClassStatic.DefaultEmpty;
sql = " set dateformat dmy; INSERT INTO dbo.AREA (";
sql += "CODE_AREA,";
sql += "NAME_AREA,";
sql += "NOTE";
sql += ") values (";
sql += "N'" + CODE_AREA + "'";
sql += ",N'" + NAME_AREA + "'";
sql += ",N'" + NOTE + "'";
sql += ")";
if (con.State != ConnectionState.Open) con.Open();
SqlCommand vCommand = new SqlCommand(sql, con);
vCommand.ExecuteNonQuery();
vCommand.Dispose();
_CodeReturn = CODE_AREA;
return 1;
}
catch
{
return 10;
}
}
public int VoidUpdate(string CODE_AREA, string NAME_AREA, string NOTE)
{
try
{
SqlCommand vCommand = new SqlCommand();
string sql = Medop.Define.Global.Static.ClassStatic.DefaultEmpty;
sql = "set dateformat dmy; update dbo.AREA set ";
sql += "NAME_AREA=N'" + NAME_AREA.Trim() + "'";
sql += " ,NOTE=N'" + NOTE.Trim() + "'";
sql += " WHERE CODE_AREA=N'" + CODE_AREA.Trim() + "'";
if (con.State != ConnectionState.Open) con.Open();
vCommand = new SqlCommand(sql, con);
vCommand.ExecuteNonQuery();
vCommand.Dispose();
_CodeReturn = CODE_AREA;
return 1;
}
catch
{
return 10;
}
}
public int VoidDelete(string CODE_AREA)
{
try
{
string sql = Medop.Define.Global.Static.ClassStatic.DefaultEmpty;
sql = "delete from dbo.AREA where CODE_AREA=N'" + CODE_AREA.Trim() + "'";
if (con.State != ConnectionState.Open) con.Open();
SqlCommand vCommand = con.CreateCommand();
vCommand.CommandText = sql;
vCommand.ExecuteNonQuery();
vCommand.Dispose();
return 1;
}
catch
{
return 10;
}
}
#endregion Public
#region Private
public DataSet VoidGetDataset(string _Input, bool CodeorAll)
{
try
{
string sql;
if (con.State != ConnectionState.Open) con.Open();
if (CodeorAll)
{
if (_Input.Trim().Equals(Medop.Define.Global.Static.ClassStatic.DefaultEmpty))
{
sql = "SELECT 0 AS STT, CODE_AREA, NAME_AREA, NOTE FROM dbo.AREA where 1=1 order by CODE_AREA,NAME_AREA,NOTE";
}
else
{
sql = "SELECT 0 AS STT, CODE_AREA, NAME_AREA, NOTE FROM dbo.AREA where 1=1 and CODE_AREA=N'" + Medop.Dispose.Conveniently.Conveniently.Replate(_Input.Trim()) + "' order by CODE_AREA,NAME_AREA,NOTE";
}
}
else
{
if (_Input.Trim().Equals(Medop.Define.Global.Static.ClassStatic.DefaultEmpty))
{
sql = "SELECT 0 AS STT, CODE_AREA, NAME_AREA, NOTE FROM dbo.AREA where 1=1 order by CODE_AREA,NAME_AREA,NOTE";
}
else
{
sql = "SELECT 0 AS STT, CODE_AREA, NAME_AREA, NOTE FROM dbo.AREA where 1=1 and CODE_AREA like N'%" + Medop.Dispose.Conveniently.Conveniently.Replate(_Input.Trim()) + "%' or NAME_AREA like N'%" + Medop.Dispose.Conveniently.Conveniently.Replate(_Input.Trim()) + "%' order by CODE_AREA,NAME_AREA,NOTE";
}
}
SqlCommand cm = new SqlCommand();
SqlDataAdapter da = new SqlDataAdapter();
DataSet mDataset = new DataSet();
cm = new SqlCommand(sql, con);
cm.ExecuteNonQuery();
da = new SqlDataAdapter(sql, con);
da.Fill(mDataset, Define.Global.Static.ClassStatic.NameTable);
da.Dispose();this.con.Close();
if (mDataset.Tables[Define.Global.Static.ClassStatic.NameTable].Rows.Count != 0)
{
_ArrayReturn[0] = mDataset.Tables[Define.Global.Static.ClassStatic.NameTable].Rows[0][Medop.Define.FieldInDatabase.StaticCatalogue.CODE_AREA].ToString().Trim();
_ArrayReturn[1] = mDataset.Tables[Define.Global.Static.ClassStatic.NameTable].Rows[0][Medop.Define.FieldInDatabase.StaticCatalogue.NAME_AREA].ToString().Trim();
_ArrayReturn[2] = mDataset.Tables[Define.Global.Static.ClassStatic.NameTable].Rows[0][Medop.Define.FieldInDatabase.StaticCatalogue.NOTE].ToString().Trim();
}
return Medop.Dispose.Conveniently.Conveniently.MakeStandardDataSet(mDataset);
}
catch
{
return null;
}
}
#endregion Private
#region Property
public string[] ArrayReturn
{
get { return _ArrayReturn; }
}
public string CodeReturn
{
get { return _CodeReturn; }
}
#endregion
}
đ
|
|
|
|
|
|
YAWT :
Yet Another WTF Topic !
|
|
|
|
|