|
While syntactically correct, executing that statement will throw an exception, since an instance of iFirstC is not of type SecondClass . If you prefer not to handle exceptions, you should use the as operator and check for null .
SecondClass iSecondC = iFirstC as SecondClass;
if (iSecondC == null) {
}
/ravi
|
|
|
|
|
You can only cast SecondClass to FirstClass, but not FirstClass to SecondClass.
FirstClass is parent, SecondClass is child.
|
|
|
|
|
Matglas wrote: Is there anyway to have a extended class and cast to it?
Only if the object is of the "extended class" (aka derived class).
The following will work:
FirstClass iFirstC = new SecondClass();
SecondClass iSecondC = (SecondClass)iFirstC;
This is because the actual object is a SecondClass even although it is initially referenced as a FirstClass .
Does this help?
|
|
|
|
|
Thanks all for the great input. I start to understand it better now. So it does help.
|
|
|
|
|
Hey.
I was wondering if any one can point me towards some resources that outline/explain the dangers associated with allowing users to upload image files to a web server.
I shall be using the MIME type as one step of validation and maybe limit uploads to jpeg so i can read the file header and associated data as validation (not fool proof i know).
Any advice on validation and the dangers will be much appreciated.
Cheers
Dan
|
|
|
|
|
Can you write me an insert statement to insert an integer and a Date data types values in dBase dbf table?
|
|
|
|
|
hi, i'm trying to make a real time audio streaming application using directSound. but the problem is i do not know how to transfer the audio bytes received to directSound buffers and eventually play it while filling in the buffer with data...please, can anyone help me out with this very big dillema...my future depends on the completion of this project.. :c
mumwei :c
|
|
|
|
|
I am writing a Windows Mobile CE 5.0 c# application, and I want my form to be completely full screen, and not movable. I have been able to make the form unmovable and maximized. However, want it to cover the task bar as well on the PDA device (it's a symbol one).
I have done some PInvoke calls to hide the task bar. But still, when setting the form WindowState property to Maximized, it does not take up the blank space left by the task bar. Any help please?
Ashvin Gunga
|
|
|
|
|
Hi,
I already worked on the problem, and it's working fine. Cheers.
Ashvin Gunga
|
|
|
|
|
Hi there,
I'm trying to Parse the Value of an Excel Cell into its correct Data Type. (I read the excel sheet then add all cell values into an object array).
Trouble is, (DateTime.TryParse(value, out newDateTime) returns false, where the Excel Value (value ) is '01/01/2007', but is passed in as '39083' - an int.
Now, I can't just assume '39083' is a valid date, as is could be a valid int.
Any suggestions?
Thanks
Jon
|
|
|
|
|
I want to sort the dataview based on the column AVG_VALUE which is of type double, i have written the following code, but it is not sorting.
DataView dv = ds.Tables[0].DefaultView;
dv.Sort = "AVG_VALUE DESC";
table structure
AVG_VALUE VARIABLE_NAME
11.1 Var1
12.2 Var2
1.1 Var5
40.2 Var6
Output Required
AVG_VALUE VARIABLE_NAME
40.2 Var6
12.2 Var2
11.1 Var1
1.1 Var5
|
|
|
|
|
If you have Spaces in your field names or Reserved words then you have to put field name in [] to get it to work.I think it should work like this:
DataView dv = ds.Tables[0].DefaultView;
dv.Sort = "[AVG_VALUE]DESC";
|
|
|
|
|
Hello,
I want to do some windows API operation from C#.
and for that i want to import user32.dll please
give me specific syntax for importing dll from the
.cs page at runtime
Rahul Patel,
Software Engineer,
Gateway Technolabs
-- modified at 6:26 Tuesday 13th February, 2007
|
|
|
|
|
[DllImport("user32")]
private static extern UInt32 GetKeyboardLayoutList(int nBuff,ref int lpList);
|
|
|
|
|
thank a lot for giving me a solution....
|
|
|
|
|
You need to use something like this:
[DllImport("user32.dll")]
< Declaration of function in user32.dll to be used here preceded by static extern >
You have to declare each function you want to use in C# code in the above manner.Moreover you should write this code where you are declaring other variables of your class which is normally at the start of the class.
After that you can use those functions in your C# code. Keep in mind that all the types used while declaring function prototypes must be C# types and must not contains Win32 or other languages types.
Regards,
Wasif Ehsan.
|
|
|
|
|
I am exporting data from A Repeater to Excel sheet and my code works fine.
But I have used 2 repeaters side by side in the table.
When I export to excel I need to get the Excel data in the same mannar as side by side.
But I am getting the other repeater data in anothe line which doesn't look good.
Any body helps me in this
Thanks
Hima
"Aim to go where U have never been B4 and Strive to achieve it"
http://groups.yahoo.com/subscribe/dotnetforfreshers
http://himabinduvejella.blogspot.com
|
|
|
|
|
Hello,
I m using Visual Studio 2005.Doing windows project in C#.Net.In that
i m using popup window forms.All details in text boxes are getting filled.But combo box and list boxes are not showing correct records?
bubuli
|
|
|
|
|
What records do ou expect them to have ? What code is setting these values for you ? you've given us nothgn to go on
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
I m taking records from database (sql server 2000) depending on the id of selected record from the datagrid.I m using Binding navigator.On that i have taken command button.On click event of that button i m displaying another form,in that form i m getting above explained problem.
bubuli
|
|
|
|
|
Have you tried debugging the application to ensure the value you're sending to the database is the correct one?
Kay Lee
-Just your average coder
|
|
|
|
|
Hi,
I am trying to write an windows application which needs to capture the text selected from other applications as well.
I would like to know how we can capture a text that gets selected when we double click on the mouse. When any text is selected in any of the applications (not only the application that i use to capture the Text value), i need to capture the text. For example when we select a text in the notepad, and double click the mouse on the application that i have created, then the text selected in the Notepad should be captured and displayed in my application. Is there a way to do this ...
Thanks in advance
CSharpbeginer
|
|
|
|
|
There's a windows API called WindowFromPoint. If you p/invoke that, you can call GetWindowText ( another p/invoke ) to get the text of the window your mouse is under. How far that will get you, I don't know.
It's odd to me, I know of no commercial software that does this, but it gets asked for so often.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hi Everyone,
I have some problem with override of background in an TextBox.
The text don't merge with background, lock at code below.
Many thanks in advance.
/Gywox
<br />
using System;<br />
using System.Drawing;<br />
using System.Drawing.Drawing2D;<br />
using System.Globalization;<br />
<br />
namespace System.Windows.Forms<br />
{<br />
public class TextBoxDate : TextBox<br />
{<br />
private DateTime date;<br />
private CultureInfo culture = CultureInfo.CurrentCulture;<br />
private bool validDate = false;<br />
private Brush backgroundBrush = new SolidBrush(SystemColors.Control);<br />
<br />
public TextBoxDate()<br />
{<br />
this.SetStyle(ControlStyles.UserPaint, true);<br />
this.backgroundBrush = new HatchBrush(HatchStyle.DarkDownwardDiagonal, Color.FromArgb(255, 128, 128), this.BackColor);<br />
}<br />
<br />
public CultureInfo Culture<br />
{<br />
get<br />
{<br />
return this.culture;<br />
}<br />
set<br />
{<br />
this.culture = value;<br />
}<br />
}<br />
<br />
public DateTime DateTime<br />
{<br />
get<br />
{<br />
return new DateTime(this.date.Year, this.date.Month, this.date.Day, this.culture.Calendar);<br />
}<br />
}<br />
<br />
protected override void OnTextChanged(EventArgs e)<br />
{<br />
base.OnTextChanged(e);<br />
Parse();<br />
}<br />
<br />
protected override void OnLeave(EventArgs e)<br />
{<br />
base.OnLeave(e);<br />
if (this.Text != string.Empty && this.validDate)<br />
{<br />
this.Text = this.DateTime.ToString(this.culture.DateTimeFormat.ShortDatePattern, this.culture);<br />
}<br />
}<br />
<br />
protected override void OnPaintBackground(PaintEventArgs pevent)<br />
{<br />
base.OnPaintBackground(pevent);<br />
if (this.Text != string.Empty)<br />
{<br />
if (!this.validDate)<br />
{<br />
pevent.Graphics.FillRectangle(this.backgroundBrush, this.ClientRectangle);<br />
}<br />
}<br />
}<br />
<br />
private void Parse()<br />
{<br />
DateTime resultDate;<br />
<br />
this.validDate = false;<br />
if (DateTime.TryParse(this.Text, this.culture, DateTimeStyles.AllowWhiteSpaces, out resultDate))<br />
{<br />
this.date = resultDate;<br />
this.validDate = true;<br />
}<br />
this.Invalidate();<br />
}<br />
}<br />
}
|
|
|
|
|
A textbox is a very nasty control. It draws itself outside it's paint message, so it's very hard to change how it looks.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|