|
Hi all
I'm new in C# development.
I've got a function with a parameter of type object that is casted to a string to be used in it.
How to test a variable before passing it to the function? There is some function making sure that a variable I'm using is a string. What checking to do?
I need to use it also with assertion in debug code.
Regards
manuStone
|
|
|
|
|
2 ways depending on how you want to play it
if(myUnknownObject is string)
{
string myString = (string)myUnknownObject;
DoStuff(myString);
}
or
string myString = myUnknownObject as string;
DoStuff(myString);
the second way will leave myString as null if myString wasn't a string so you'll have to check for nulls in DoStuff, but you'd do that anyway as a string could be null. The difference is whether a null string has a significance in your application.
HTH
Russell
|
|
|
|
|
Hi Russel
thank you very much for your quick response.
Have a nice day
manuStone
|
|
|
|
|
Additional to arachnoids second solution you may also do this:
if(obj is string)
DoStuff((string)obj);
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
I've got a WebBrowser control and when I do a:
browser.Navigate("http://some.url")
it will work fine the first time, but a subsequent call to the same URL will ALWAYS return instantly with the locally cached copy... when what I really want it to do is a complete new download.
How do I force browser.Navigate to ignore the local system cache??
Just for grins, I tried setting:
browser.Refresh(WebBrowserRefreshOption.Completely)
just after the InitializeComponent method, hoping it would force the control to bypass the cache, but it didn't (and according to the documentation, this just does a refresh and doesn't set the DocumentCompleted event anyway...) but I couldn't find anything else that might bypass the cache and force a reload.
What am I missing?
Thanks!
-Dan
|
|
|
|
|
|
Excellent suggestion... not sure why I didn't think of it... . Not real elegant, but works perfectly! Thanks for the tip and quick reply!
-Dan
|
|
|
|
|
Hi everybody! I want to read memory and pin information of smartphone or PDA but i don't know what function can be used in C#. I found in MSDN but it in Visual C++. Now i wonder either i can do it in C# or not. Please help me!
Thank.
|
|
|
|
|
Hi All,
Here i want to execute an .exe file on particular button. Plz hlep
Regards:
Suveen
|
|
|
|
|
Process.Start(string exeName); is probably the best way. I can't remember the namespace, but it's probably in System.Diagnostics
|
|
|
|
|
PRocess.Start will start any exe for you.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hi,
I need to add motion blur effect to my image. Did anyone know the code for this in c#.
Thanks
|
|
|
|
|
This article might help (as a starting point).
http://www.codeproject.com/opengl/MotionBlur.asp[^]
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Hi,
I have seen that code .But it is in c++.
|
|
|
|
|
My image processing libraries are in C sharp. You should be able to read those, and this article, and work out how to port the code. Then, you can write your own article ç'=
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Motion blur is an efect obtaind by exposing a moving object to a reciver for a longer period of time, in witch the object changes it's position.
So, if your image is static and you want to generate a "blurred" version of it I wold recommend you to add to a new ARGB image the original one and with an different alpha value the same image with different displacements, depending on the desired effect. Suposing you want the image to look like moving in a line you would and a sequence of alpha images at diferent y (or x) coordinates (depending on the "speed"). Or for instance if you want your immage to look like an "earth-quake" one, do like in the line instance, but in the + and - direction of the x coordinate (or the floor line).
I hope this helps.
protected internal static readonly ... and I wish the list could continue ...
|
|
|
|
|
How do i detect if windows is using themes or classic mode?
I'm building a control which needs to have 2 comboboxes touching each other(or nearly). If I make them touch in my development environment(windows classic) then they overlap under XP styles. If I make them touch in XP styles there are huge gaps in Windows Classic.
Is there an easy way to find out which mode i'm in or what the drawable area of the control is?
Thanks
Russ
|
|
|
|
|
|
thank you,
Just what i needed.
Russell
|
|
|
|
|
Greeting,
I made a solution with some projects.
Every project has it's own namespace.(ie,ns1,ns2,...)
When I want to use a namespace(ex in ns2 i want to use ns1) with this instruction :
using ns1;
at compile or build time this error occurred :
he type or namespace name 'ns1' could not be found (are you missing a using directive or an assembly reference?)
What I should to do to solve this problem?
Regards
|
|
|
|
|
have you referenced the project that contains a namespace from the one using it?
russell
|
|
|
|
|
I have a windows application of which I want to validate a survey data that was captured using another software and stored in an MS SQL server 2000 database table.
eg. I have three columns , Sex, Age, Marital status
if a person is less than 20 years and is reported to be married,
I have to fire the message that is the person is too young to be married. I was able to do that in VB 6.0:
This is the code snippet that was used in vb 6.0, I had a richtextbox object where I placed all the error messages.
-------------------
Dim adoTest As New ADODB.Connection
Dim rstTest As New ADODB.Recordset
Dim adoSearch As ADODB.Recordset
Dim census, i As Integer
Private Sub cmdTest_Click()
cd.ShowSave
rtb.SaveFile cd.FileName
End Sub
Private Sub Form_Load()
adoTest.CursorLocation = adUseClient
adoTest.Provider = "MSDASQL.1"
adoTest.ConnectionString = "Password=sa;Persist Security Info=True;User ID=sa;Data Source=LSA2006;Initial Catalog=LSA2006"
adoTest.Open
If adoTest.State = adStateOpen Then
MsgBox "Connexion with the server established", vbInformation, "Testing"
Else
MsgBox "Connexion Failed !", vbInformation, "Testing"
End If
rstTest.Open "select * from table2", adoTest, adOpenDynamic, adLockOptimistic
rtb.Text = ""
While Not rstTest.EOF
If rstTest!married = 1 And rstTest!age <= 15 Then
If rtb.Text = "" Then
rtb.Text = rstTest!id
Else
rtb.Text = rtb.Text & vbNewLine & rstTest!id & " Too young to get married"
End If
End If
If rstTest!age <= 20 And rstTest!education >= 3 Then
If rtb.Text = "" Then
rtb.Text = rstTest!id
Else
rtb.Text = rtb.Text & vbNewLine & rstTest!id & " Age not consistent with education"
End If
End If
rstTest.MoveNext
Wend
End Sub
-------------
Can anybody help me how to do this in C#. I have to do data validation quickly
Thank you
phokojoe
|
|
|
|
|
which bit are you haveing problems with?
I assume the problem is going to be with getting data from the db and getting your hands on the data.
Create a connection
Create a command containing your select command
assign the connection to the command
call executereader() on the command
datareader dr = myCommand.ExecuteReader()
while (dr.Read())
{
do stuff with dr fields
}
HTH
Russ
|
|
|
|
|
Yep!
Thanks a lot. It worked but to a certain level. I maneged to retrive just 1 record/column before I intoroduce the if statement. I have about 127 records at present, but when I introcude the if statement to compare the values and then display them in the richtextbox, I get the message on the if statement
"An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll
Additional information: Input string was not in a correct format."
this is the code
try
{
string str = "select * FROM table1";
con = new SqlConnection(_connect);
cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = str;
// Open the Connection
con.Open();
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
while (dr.Read())
{
if (System.Convert.ToInt32(dr[10]) < 20)
{
rtb.Text = dr[7].ToString();
}
}
}
catch(SqlException ex)
{
MessageBox.Show(ex.Message);
}
finally
{
// Close the Connection object
con.Close();
}
I am comparing column 10 with the age of the person that is 20 and then display the id of that particular record in textbox which is in column 7.
Can you please point where I am doing the wrong thing
Cheers!
phokojoe
|
|
|
|
|
sounds like it might be a rich text box problem to me. I only tried to use them once and found them too tricky for what i needed.
add a multiline textbox to your form and try putting the data in that just to check that all the logic is working.
Russ
|
|
|
|