Browsing 7239 questions and answers with Jon Skeet

interpreting and reading any file type in c#

I have opened a file in Notepad++ and it looks like the attached image. What do these symbols represent? Hex/Ascii/Binary? I would like to read and write to a separate file. I...
Jon Skeet
people
quotationmark

If you just want to copy the exact binary data, without caring whether it's text or not, you should be using Stream. For example: using (var input = Stream.OpenRead(inputFile)) using (var output = Stream.OpenWrite(outputFile)) { ... more 11/14/2013 2:54:41 PM

people

Why my date is written 0000 00 00

I have a table where the date column name is defined as proddate and defined as DATE. Here is the code I write the value into table: cmd.Parameters.Add("@Mydate",...
Jon Skeet
people
quotationmark

In the first version, you're converting your value to a DateTime and then to a string, using the default format for a DateTime value. MySQL is then trying to parse that, and presumably failing. In the second version, you're parsing your... more 11/14/2013 2:50:27 PM

people

Why do c# objects once behave like passed by value and once as passed by reference?

I don't understand one thing about passing parameters to methods in c#. From what I see objects in c# sometimes behave like the have been passed by reference and once as if they...
Jon Skeet
people
quotationmark

Objects aren't passed at all. For expressions of a reference type (classes, interfaces etc) references are passed - by value by default, but the variables are passed by reference if you use ref. It's important to understand that the... more 11/14/2013 2:34:09 PM

people

C# Activator.CreateInstance Error

Main class .... using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1{ class...
Jon Skeet
people
quotationmark

Activator.CreateInstance(string, string) doesn't do what you think it does. The first parameter is the assembly name. The second parameter is the fully-qualified type name. So you should have: string className =... more 11/14/2013 2:10:17 PM

people

Is File.ReadAllText thread safe?

Specifically will spawning a thread using the TPL Task.Factory.StartNew: Task.Factory.StartNew(() => { File.ReadAllText(@"thisFile.txt"); }); Causing any issues, etc?...
Jon Skeet
people
quotationmark

It's fine - assuming nothing's writing to the file at the same time, in which case you may not be able to open the file (or might see partial writes). As per the documentation of File: Any public static (Shared in Visual Basic)... more 11/14/2013 11:28:01 AM

people

How to reconstruct an object from byte[] not created from ObjectOutputStream?

I need to reconstruct an object on the client side from a byte[] which stores bytes coming from an InputStream(TCP/IP). The Server is in C and structures are sent across as bytes....
Jon Skeet
people
quotationmark

But this method is tedious and I was wondering if there is an easy way out? Not that I'm aware of. But if you find yourself writing the same code multiple times, you may well find that if you extract some helper methods it actually... more 11/14/2013 10:34:11 AM

people

MethodBase.IsConstructor does not work as specified with a static constructor

Just a simple observation. The property MethodBase.IsConstructor does not work with static constructors, and the documentation does not mention this fact (quote: "true if this...
Jon Skeet
people
quotationmark

"Static constructor" is really just C# terminology. In .NET itself, there's a type initializer (as per Type.TypeInitializer). A type can have a type initializer without having a static constructor declared in C# - e.g. for static variable... more 11/14/2013 10:23:35 AM

people

no suitable method found for getInstance error in java mail api

I am using java mail api to send the mail but stuck with the following error .. no suitable method found for getInstance(java.util,Properties,java.net.Authenticator) And here...
Jon Skeet
people
quotationmark

The problem is that you've imported java.net.Authenticator instead of javax.mail.Authenticator. Look at the types specified in the error message, then look at the parameter types in the documentation for Session.getInstance. more 11/14/2013 10:08:24 AM

people

Equals gives TRUE comparing two different objects

I dont understand, why the following equals result is true. This example comes from msdn: Dim sb1 As New StringBuilder("abc") Dim sb2 As New StringBuilder("abc", 16) ...
Jon Skeet
people
quotationmark

Could anyone explain to me why the result in the first example is true? Because StringBuilder overloads Equals: Return Value Type: System.Boolean true if this instance and sb have equal string, Capacity, and MaxCapacity... more 11/14/2013 9:41:19 AM

people

Explain the error: "constructor … cannot be applied: actual and formal differ in length"

Please help me fix this error: constructor CollegeMember in class C10h1.CollegeMember cannot be applied to given types; required: java.lang.String,java.lang.String; found:...
Jon Skeet
people
quotationmark

The problem is your Student constructor. It needs to chain to the CollegeMember constructor, which it should do like this: public Student(String name, int year, String telNumber) { super(name, telNumber); this.year =... more 11/14/2013 6:33:51 AM

people