You searched for how does c# work. We found 81 results in 0.231 seconds.

How to TryParse for Enum value in NET 3.5?

I have to work with .NET 3.5 but want to use TryParse method which I know belongs to .NET 4.0. Then I searched the web for the subject and I think I found the best solution in...
Jon Skeet
people
quotationmark

As the error message is saying, you need to pass the type of the enum as the first argument. You also need to change the type of myValue to match the out parameter of EnumTryParse, so: object myValue; if... more

people

Why anonymous method can be pass to a delegator's constructor?

Action<int, string> s = new Action<int, string>(delegate(int a,string b){}); Action<int, string> ss = delegate(int a, string b) { }; Why these both work? Why...
Jon Skeet
people
quotationmark

You're not really making a constructor call in the normal way, even though that's what it looks like. Instead, this is a delegate-creation-expression as described in the C# 5 specification, section 7.6.10.5: A... more

people

How can I guarantee that an interface and a class method parameters match without manually checking?

I recently noticed a bug due to a mismatched parameter order in the class to its interface parameter order. I felt that this should have been a compile error. I found out that...
Jon Skeet
people
quotationmark

Is there a way to guarantee at build time that a class matches the interface parameter names? I would prefer not to do this manually. Not within the C# language. However: You could write a unit test to check, reasonably easily. Not... more

people

How to create a Method that creates a new List and takes additional parameters

Is there a way to create a Method that creates a new instance of a List as a Method Parameterand does something with the new List? private void...
Jon Skeet
people
quotationmark

It sounds like you should be returning the list reference, rather than using it as a parameter - otherwise the fact that you're assigning a different value to it in the first statement of the method body makes it pointless: private... more

people

DateTime Format provider for filepath

I have a file-path that's been created from DateTime stamp: "C:\\Logs\\Tests\\2015\\Mar\\24\\13_32_09\" Now I am trying to convert my file-path back to DateTime object. With...
Jon Skeet
people
quotationmark

No, you don't need to create an IFormatProvider at all. The invariant culture is fine for this (assuming the month name is always in English). You can just use DateTime.ParseExact, passing in the appropriate custom format string (quoting... more

people

Representing signed byte in an unsigned byte variable

I apologies if the title of this question is not clear, but i cannot figure out the best way to describe my predicament in so few words. I am writing a communication framework...
Jon Skeet
people
quotationmark

You basically don't need to do anything except stop thinking about bytes as numbers. Think of them as 8 bits, and Java and C# are identical. It's rare that you really want to consider a byte as a magnitude - it's usually just binary data... more

people

TextBlock insists on showing &quot; instead of " in metro app

I'm trying to get a Text description from a website and used this code HttpResponseMessage response1 = await httpClient.GetAsync(url); ...
Jon Skeet
people
quotationmark

You're calling Replace but not doing anything with the result - strings are immutable in C#, so the Replace method doesn't change the contents of the existing string. As the documentation states: This method does not modify the value... more

people

What is the C# equivalent to VB.NET's CType Function for use with generic types?

Assume I have a table called MyTable in a SQL Server database called MyDB with the following three records: |ID|MyVarcharColumn| -------------------- |1|123| |2|2014-10-01 9:58...
Jon Skeet
people
quotationmark

If you only need to support a very specific set of types that are supported by it, then Convert.ChangeType may be okay: object value = (string) ds.Tables[0].Rows[0]["MyVarcharColumn"]; return (T) Convert.ChangeType(value,... more

people

How do I make the weird characters in Spanish go away? It persists even after changing JDB URL to UTF 8

I see words such as súbito, autónomo. Why aren't they proper. I had a problem while entering all Russian characters via JDBC into the MySQL database. The problem there was that...
Jon Skeet
people
quotationmark

Well this is probably the first problem: InputStreamReader reader1 = new InputStreamReader(in); That's loading the file using the platform default encoding, which may or may not be appropriate for the file in question. Likewise... more

people

Parse class variables?

I'm pretty new to c# language as I just started to use it several weeks ago, and I came across one simple problem with classes.I was sitting for good 30 minutes looking for...
Jon Skeet
people
quotationmark

I think you're confused about what your methods are doing, and when you're initializing objects. I suspect you actually want to do something like this: class Program { static void Main(string[] args) { // Ask the user for... more

people