|
Skippums wrote: I see it as being handy when you create a new object of some type using reflection, when you don't know the type beforehand.
The thing is the compiler has to know the type. If it isn't an anoymous type (where the actual type is known only to the compiler) then you and the compiler should know the same thing. (I wrote a blog entry on what happens under the hood with anonymous types[^])
Skippums wrote: public void SomeMethod(object someObject) {
var foo = (someObject.GetType())someObject;
foo.Add(...);
}
I don't have VS2008 in front of me, but I doubt that is possible. The cast must be a literal or known at compiler time. This isn't.
|
|
|
|
|
Colin Angus Mackay wrote: I wrote a blog entry on what happens under the hood with anonymous types[^])
great one.. Thanks. I have subscribed your feed. Thanks..
Thanks and Regards,
Michael Sync ( Blog: http://michaelsync.net)
"Please vote to let me (and others) know if this answer helped you or not. A 5 vote tells people that your question has been answered successfully and that I've pitched it at just the right level. Thanks."
|
|
|
|
|
Michael Sync wrote: 1. Why do we need "Implicitly typed local variables" (similar to "var" in JS)? Is it created especially for LINQ?? If LINQ is not used in the application, this kinda variable won't be required anymore, isn't it?
They are only needed when the variable type is created in the compilation, so that it's impossible for you to explicitly declare a reference for it.
Michael Sync wrote: 2. Let's say I wrote like that "var myvar = 1;". then, C# compiler will assume my variable "myvar" is int, right? Actually, I declared it as long.. What about "int vs uint", "long vs ulong" and "double vs float vs decimal"??
The compiler will not assume that the variable is an int. The variable is an int, as you have specified a literal int value for it.
If you want a different data type, you have to specify a literal value of a different type. Like:
var first = 1U;
var answer = 42L;
var big = 1234567890UL;
var pi = 3.1416;
var size = 12.5F;
var price = 27.99M;
However, you should really never use this syntax with numeric literals, as it's not very obvious what the data type is.
A possible use where it makes sense, is where the data type is actually stated in the statement so that it's superflous to repeat it, like:
var b = new System.Web.UI.HtmlControls.HtmlInputRadioButton();
vs.
System.Web.UI.HtmlControls.HtmlInputRadioButton b = new System.Web.UI.HtmlControls.HtmlInputRadioButton();
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
thank you, Guffa. I'm clear now..
Thanks and Regards,
Michael Sync ( Blog: http://michaelsync.net)
"Please vote to let me (and others) know if this answer helped you or not. A 5 vote tells people that your question has been answered successfully and that I've pitched it at just the right level. Thanks."
|
|
|
|
|
I have a c# app that stores pdfs. I'd like to run a routine against the pdfs that changes them to searchable pdfs. Does anyone know how to accomplish this - I have adobe 8 on the server and not sure if there are any apis.
|
|
|
|
|
Hi,I'm writing a project in visual .net with C# platform and i want to use ReportViewer for creaing my reports,but I would like to know that how i can write codes in my ReoprtForm.cs for setting ReportViewer properties as like as page setup,setting margin ,fonts ,printing and so on ...
Thanks,
D.Riazi
D.Riazi
|
|
|
|
|
|
Hi, thanks for your response.but i don't want to creat any Report with Crystal Reporter.
I want to use Object Reporting with ReportViewer tool in C#.
D.Riazi
|
|
|
|
|
hi
In One System I am having One webservice.and in another system i have developed one Application that contain Only one textbox.
Actually in previous senario v r writing exceptions in eventlog or in trace.
but in my case,it has write tht perticular exception directly into TextBox with out saving r using files.please give me some suggestions to do.
thanks in advance
regards
prasanna
prasanna
|
|
|
|
|
Hi,
i have an c# Form implements AxMozillaBrowser control and
try to call the navigate method.
But I get the following error: "The operation timed out when attempting to contact http://www.google.de".
Im behind a proxy server. I put the proxy values in "about:config" .
Has anybody an idea?
thx in advance
|
|
|
|
|
Hi
Can any one tell me how to upload an Excell file to FTP using c#.
Thanks in advance
Prakash
PR
|
|
|
|
|
Uploading to an ftp doesn't depend on the type of file, it's the same process for all files. Did you try searching on google or codeproject? There are lots of examples showing how to do it
|
|
|
|
|
Following code is working fine for word document
but incase of excel it is in binary format
// Get the object used to communicate with the server.
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://172.22.4.14" + @"/" + "E3764_DetailedLevelDesign.doc");
request.Method = WebRequestMethods.Ftp.UploadFile;
// This example assumes the FTP site uses anonymous logon.
request.Credentials = new NetworkCredential("Danaher", "Motion$123");
// Copy the contents of the file to the request stream.
StreamReader sourceStream = new StreamReader("c://E3764_DetailedLevelDesign.doc");
byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
sourceStream.Close();
request.ContentLength = fileContents.Length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(fileContents, 0, fileContents.Length);
requestStream.Close();
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription);
response.Close();
when i try to open the excell file in IE it is not in redable format.
|
|
|
|
|
Reddy Prakash wrote: StreamReader sourceStream = new StreamReader("c://E3764_DetailedLevelDesign.doc");
byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
You are reading the file as if it was a text file, this doesn't work for any binary file. If you have managed to open .doc files uploaded with this code, you have only been lucky that the files have not been too badly corrupted.
Use the File.ReadAllBytes method to read the file into an array.
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
Thank you Guffa
|
|
|
|
|
Hi
How to start service in setup progress
i deploy a setup application for service
it's install but service don't start
i should manually start service
Finally
i would like to start service in installation progress(Amount Of Install)
Thanx
Boroumandan
|
|
|
|
|
Your are putting same question again and again !!! try to work arround the same question !!!
|
|
|
|
|
Hi it's my first post on this board, so "hello Everyone ".
I have a problem with new thread I need for my program. I must create new thread with socket parameter. On this page I found a way to pass a parameter. But this just not work for me.
This is some of my code program. It's lame so please don't mind.
This is a fragment of my new thread:
private static void Thread_Send_Recv(Socket w)<br />
{<br />
klient k = new klient();<br />
string dane;<br />
byte[] buf = new byte[255];<br />
while (true)<br />
{<br />
try<br />
{<br />
w.Receive(buf);<br />
dane = Encoding.UTF8.GetString(buf);<br />
string[] split = dane.Split(new Char[] { ',' });<br />
<br />
if (split[0].ToString() == "LOGIN")<br />
{<br />
string n, message;<br />
bool all_ok = true;<br />
byte[] m = new byte[255];<br />
<br />
n = split[1].ToString();<br />
<br />
...
And this is thread that invoke previous thread:
private static void Thread_Accept()<br />
{<br />
while (true)<br />
{<br />
s1 = s.Accept(); <br />
sockety.Add(s1);<br />
Console.WriteLine("Wykryto polaczenia z adresem: " + s1.RemoteEndPoint);<br />
ParameterizedThreadStart pts = new ParameterizedThreadStart(Thread_Send_Recv);<br />
Thread sr = new Thread(pts);<br />
sr.Start(s1);<br />
}<br />
}
When I try to compile this I get a strange error:
No overload for 'Thread_Send_Recv' matches delegate 'System.Threading.ParameterizedThreadStart
Why is that? I know that Socket isn't exactly a Object in parameters of Thread_Send_Recv but when I change it for an Object, it says that object don't have such methods as Recive(), Send(), etc. How to change it so it can work. Sorry for my bad English;P.
Thanks in advance for any word of help
|
|
|
|
|
You need to change the parameter's type to Object, like you describe. This is the "signature" of the ParameterizedThreadStart delegate, so you can't change this.
Now, since your parameter is now of type Object (and not Socket) then it does not have the methods/properites of the Socket type. Since you know that you passed in an object of type Socket (which is currently being held in a parameter of type Object), you can simply cast it to the appropriate type. So something like this:
private static void Thread_Send_Recv(Object obj)
{
Socket w = obj as Socket;
if (null == w)
throw new ArgumentException(...);
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Great, it works!
Thanks very much!!
|
|
|
|
|
I have a bunch of strings representing time spans, typical values being "6.0 months" and "3.0 years". Is there a way I can convert these into TimeSpan values so I can sort them correctly?
TimeSpan.Parse() is not quite what I want. Is there some other method in the framework or a third party library (I STFWed) or do I have to write my own?
Cheers,
विक्रम
And sleep will come, it comes to us all
And some will fade and some will fall
|
|
|
|
|
Sorry mate, but you're going to have to write your own converter for them.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
I feared as much and have rolled out half the code. I don't really look forward to doing the rest of it tomorrow.
Cheers,
विक्रम
And sleep will come, it comes to us all
And some will fade and some will fall
|
|
|
|
|
Hi Guys. I have managed to get some code to export data in my Access DB to a CSV file. Now, I have two small issues.
1. I want to mark all the records as they are exported to Y in a column named exported and only export all the records marked as N. Anybody have a suggestion on how I could do this in the export code?
2. When I open the CSV file in Excel I get a few errors. First error says that the file is in a different format than the one specified by the extention. It allows you to continue and then comes up with error "Cannot read the 1st record. The it reports yet another error which says that Excel has determined the file to be a SYLK file but not load it" but it still imports the data into Excel. Any ideas on how I get past this?
Code below:
private void toolStripButton2_Click(object sender, EventArgs e)
{
StreamWriter sw = new StreamWriter(@"C:\nefz.csv", false);
DataTable dt = m_dtCallCentre;
int iColCount = dt.Columns.Count;
for (int i = 0; i < iColCount; i++)
{
sw.Write(dt.Columns[i]);
if (i < iColCount - 1)
{
sw.Write(";");
}
}
sw.Write(sw.NewLine);
foreach (DataRow dr in dt.Rows)
{
for (int i = 0; i < iColCount; i++)
{
if (!Convert.IsDBNull(dr[i]))
{
sw.Write(dr[i].ToString());
}
if (i < iColCount - 1)
{
sw.Write(";");
}
}
sw.Write(sw.NewLine);
}
sw.Close();
}
I was advised earlier by oneof the guys to go into the DB and run the export from there. This would defeat the pupose of writing code I think so if anybody else can help me out with this then I would greatly appreciate it.
|
|
|
|
|
Is it not the case with respect to 2 that Excel is expecting a comma separated file, but you are using semicolons to delimit the fields?
Regards,
Rob Philpott.
|
|
|
|