|
michal.kreslik wrote: Why string[] is compatible to object[] while int[] is not?
string and object are reference types (defined as class ) whereas int is a value type (defined as struct ). Obviously it's not possible to simply cast an array of value types to an array of reference types. I guess that's due to the necessary boxing of array items.
I agree that the use of CopyTo isn't the most elegant solution but I think there's no other way when dealing with value type arrays.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Actually, after some fiddling, I've found a way how to do it.
You don't need to "cast" the type if you use a generic method:
class Program
{
static void MyMethodWithUnknownInputType<T>(T[] Argument)
{
Console.WriteLine("Current input type is: {0}", Argument.GetType().ToString());
Console.WriteLine("Array contents:");
foreach (T Item in Argument)
{
Console.Write("{0} ", Item.ToString());
}
Console.WriteLine("\n");
}
static void Main()
{
string[] MyStringArray = { "String1", "String2", "String3", "String4", "String5" };
int[] MyIntArray = { 2, 4, 8, 16, 32 };
MyMethodWithUnknownInputType(MyStringArray);
MyMethodWithUnknownInputType(MyIntArray);
}
}
The output of this program:
Current input type is: System.String[]
Array contents:
String1 String2 String3 String4 String5
Current input type is: System.Int32[]
Array contents:
2 4 8 16 32
Michal
-- modified at 18:36 Wednesday 13th September, 2006
|
|
|
|
|
How to implement a drawer control in C#?like the VS Toolbox?and the auto-docking control,like the solution explorer?Can those be made manully?
|
|
|
|
|
Actually I also wanted to know that ....please anyone help us both....
<marquee>nishu
|
|
|
|
|
Hi,
I am writing a application where I need my form to be at fixed location and of fixed side. This means it should not be possible for user to move the from one location to another. How can I do this?
Regards,
Hemant.
|
|
|
|
|
Fixed size : Set property FormBorderStyle to Fixed... (Single, 3D, etc.)
Fixed Location: Use event handler "Move", in this event handler just set your location, that means every time the users move this fenster, it will be reset to it start location.
|
|
|
|
|
Hi,
I am trying to access unmanaged memory which allocated from a dll function.
The function signature that is exported is as follows
extern "C" __declspec( dllexport ) BOOL ResizeImage(LPVOID pbySrcBytes,<br />
LONG lnSrcSize,<br />
LPVOID pbyDestBytes,<br />
LPLONG lnTgtSize<br />
);
Through the parameter "pbySrcBytes" I pass memory to the unmanaged code using marshalling.
In return the unmanaged function returns memory through "pbyDestBytes" on unmanaged heap which is having dynamic size which I get through "lnTgtImgSize".
I am not able to copy the memory returned. I am getting an error as "Access Violation" & "the memory is corrupted".
I have imported the function as follows.
[DllImport("ImgProcessor.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]<br />
public static extern Int32 ResizeImage([Out] byte[] pbySrcImgBytes,<br />
Int32 lnSrcImgSize,<br />
IntPtr ppbyDestImgBytes,<br />
[Out] IntPtr lnTgtImgSize<br />
);
I have done the C# part as follows:-
byte []byInputArray = File.ReadAllBytes(txtInput.Text);
Int32 nTgtImgSize = new Int32();<br />
IntPtr ptrTargetImageBytes = Marshal.AllocHGlobal(4);<br />
IntPtr ptrTgtImgSize = Marshal.AllocHGlobal(4);<br />
IntPtr ptrSourceImageBytes = Marshal.AllocHGlobal(byInputArray.Length);<br />
Marshal.StructureToPtr(byInputArray[byInputArray.Length-1], ptrSourceImageBytes, false);<br />
ImageResizerClient.ResizeImage(byInputArray, (int)byInputArray.Length, 400, 300, ptrTargetImageBytes, ptrTgtImgSize);<br />
nTgtImgSize = Marshal.ReadInt32(ptrTgtImgSize);<br />
byte []byOutputArray = new byte[nTgtImgSize];<br />
Marshal.Copy(ptrTargetImageBytes, byOutputArray, 0, nTgtImgSize);
The Marshal.Copy method call is throwing the error.
Can anyone help me understand why this is happening?
Thank You,
Amit.
-- modified at 23:59 Monday 11th September, 2006
|
|
|
|
|
Hi,
I am writing a application where I need my form to be at fixed location and of fixed side. This means it should not be possible for user to move the from one location to another. How can I do this?
Regards,
Hemant.
|
|
|
|
|
Use FormBorderStyle property of form ,make it fixed so that it will not allow user to change the size of the form and for moving i dont have any idea.
nishu
|
|
|
|
|
Thanks !
Your solution works perfectly !. My form is now non resizable but it is still movable !
how to make from non movable
Regards,
Hemant Kulkarni
|
|
|
|
|
Hi,
in the InitializeComponent-function set a absolute position where the form should located and add a handler for the Move-Event.
<br />
this.Location = new Point(10, 10);<br />
this.Move += new EventHandler(Form1_Move);<br />
In this function set also the absolute location. Now it's not possible to move the form, but it's not the finest solution.
Regards
Inikaa
|
|
|
|
|
use TopMost property...
<marquee>nishu
|
|
|
|
|
Support there is a table in SQL server database with primary key column which is an auto-increment numeric value.
Whenever we insert any row in the table we do not supply the value of primary key column; assuming that it will be automatically generated by the databse.
I insert the column programatically using C#. I need to know the autokey assigned to the last row that i've inserted. What is the best method to find that out.
Imtiaz
|
|
|
|
|
Your requirement is not quite clear, if you want to get the last autogenerated ID, then you can get it with @@IDENTITY.
Best Regards,
Apurva Kaushal
|
|
|
|
|
u can access the autokey of the last row inserted in the database by using the C# code for @@Identity. it is same like you use in Sql Server2000. please check for the correct syntax
sAqIb
|
|
|
|
|
I write a windows forms application. My form will be in english and another language. Form's neutral language is not english. when i try to load english resources the application can not load english resources and loads neutral(it does not throw an exception). I can see the form in English in design time by changing language property. So the resource file is not corrupted. How can i fix the problem? Thanks for the help
|
|
|
|
|
Use an overload that takes a CultureInfo object or change the current UI culture (Thread.CurrentThread.CurrentUICulture ) before loading resources.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Hi
Am a newbie to Remoting.SO tried to run an appln(Client-Server) downloaded from net.But i got error while proceeding.The link is given below(Sample 2:Two GUI Clients and a Server Application)
http://www.jot.fm/issues/issue_2004_01/column8.pdf[^][^]
I get error as "underlying connection closed" while trying to run the client2,when the coordinates of X and Y are retrieved from the server,to draw the rectangle(OnPaint Method).
Please help me how to debug applications with threads like the above one.Also please tell me a solution about why i got this error.
Thanx....
|
|
|
|
|
Hi,
I have a field in SQL Server 2005 of type money. What is the corresponding DbType? Is it Currency or Double?
Regards,
ma se
|
|
|
|
|
Double can be used to round off a value to more then 2 decimal. Currency not.
Thus, currency is the same as money as DBType.
It will be a save bet to make the DB field in your database a 'money' field, and then to save the value in it's 'current' state.
When displaying the value in your code, you can round it off, by converting it to Double.
|
|
|
|
|
Hi there,
I would like to show a modal dialog and still be able to close/minimize/maximize my main form. Is there a way to accomplish this?
I'm thankful for your help.
|
|
|
|
|
Run your Model dialog in a saperate thread instead of running it from main application. YOu have to start a new thread to show your model dialog box.
Regards,
Amit Kumar
HDISM, PGDCA, MCP, MCAD, MCSD
amit_chikara2002@hotmail.com
|
|
|
|
|
Hi,
use forms TopMost property and set it to true.
hope this works.
Nitin...
|
|
|
|
|
Hi All,
Im fairly new to C#.
When I load a image as background to my form, and I place some controls on top of the form; the loading is very slow. painfully slow.
How do I achieve what i need? I want to have a background image, for the form, but have some controls on the form that load faster, and do not take much time to refresh....???
B
|
|
|
|
|
Hi,
If you set the background image at desing time it the painting of your form can take a little longer.Try using this code:
<br />
static Image image = Image.FromFile(Application.StartupPath+"\\image.jpg");<br />
private void frmMain_Paint(object sender, System.Windows.Forms.PaintEventArgs e)<br />
{<br />
e.Graphics.DrawImage(image, 0, 0, new Rectangle(0, 0, image.Width, image.Height), GraphicsUnit.Pixel);<br />
this.SuspendLayout();<br />
for (int i = 0 ; i < this.Controls.Count ; i++)<br />
this.Controls[i].Update();<br />
this.ResumeLayout(true);<br />
}<br />
Do your best to be the best
|
|
|
|