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

Decryption negating special character like " !@#$%^&*()"

I was wondering how am i able to negate away the special character. For example when i key aaa for my decrypted text and move 3 space behind, it shows it ^^^ instead of www. Is...
Jon Skeet
people
quotationmark

The problem is with this piece of code which does the actual shifting: if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) { temp = (int)(a[i] + shift); if ((c >= 'A' && c <= 'Z'... more

people

How to parse an xml file and return default value if no element found

I wrote a simple method in C# to parse a given xml file and return the value of a specific node. It works fine but I'd also like to return a default value if the node is not found...
Jon Skeet
people
quotationmark

Let's start by getting rid of the exception "handling". The node not being found is a "reasonable to expect" error, and one we're going to ensure doesn't result in an exception. Other exceptions - such as the file not being found at all,... more

people

Using generic interface as typeparameter for a method or function

Assuming the following interface which I use to define the parameter type and return type for a stored procedure... public interface IStoredProcedure<out TReturn, out...
Jon Skeet
people
quotationmark

You need to use the type arguments where you specify the interface: public static void DoAction<TReturnType, TParameterType> (IStoredProcedure<TReturnType, TParameterType> procedure1) where TReturnType : class where... more

people

What thread runs the code after the `await` keyword?

Let me just post a simple example: private void MyMethod() { Task task = MyAsyncMethod(); task.Wait(); } private async Task MyAsyncMethod() ...
Jon Skeet
people
quotationmark

Does a new thread get created to run //Code after await? Maybe. Maybe not. The awaitable pattern implementation for Task runs the continuation (the bit after the await expression) using the synchronization context which was "current"... more

people

Parameter constraints call method to check type in constraint?

I have a method with a generic parameter: internal void DoSomething<T>(T workWithThis) { } I now want to constrain this method to only accept parameters which inherit one...
Jon Skeet
people
quotationmark

Why is the compiler preventing me from doing that, based on my understanding there is no reason for it not to work The compiler is preventing you from doing it because you're trying to do something which isn't supported by C# as a... more

people

Stacking namespaces can't be referenced just like any other element?

So here is a snippet I made where one namespace in inside another (B is inside A). Usually when you use 'using SpaceA;' you can access all elements without typing SpaceA. This is...
Jon Skeet
people
quotationmark

Usually when you use 'using SpaceA;' you can access all elements without typing SpaceA. Only the direct types which are members of SpaceA. A namespace-or-type-name is never resolved using a namespace in a normal using directive and... more

people

c# mock object with private constructor, initialized via a static factory method

I am testing the following controller: public class MyController : ApiController { private readonly IUserManager _users; private int num = 0; public...
Jon Skeet
people
quotationmark

You don't need to mock User - you can use the real User class. You only need to mock (or fake) IUserManager. Your mock/fake IUserManager can use User.CreateUser to create the User objects to be returned to your controller. Unless the User... more

people

Can signed bytes be read from a stream?

I'm trying to read bytes sent by a java servlet into a C# application, so far, I haven't been able to get anything more than gibberish from the servlet using normal streams in C#....
Jon Skeet
people
quotationmark

Two problems: You're using the platform-default encoding in both C# and Java. That's almost always a bad choice. Specify the encoding explicitly in Java - UTF-8 is usually a good choice. (That's also the default for most .NET... more

people

Returning a list that is filtered based on another list in C#

Im quite new to C# so trying to test a simple string filter but not getting the desired results. This is my test method: [TestMethod] public void Test_ExceptFilter() { ...
Jon Skeet
people
quotationmark

The problem is that you're using Any with a negative condition - which means you'll include the value if there are any words that aren't included in the candidate. Instead, you want to think of it as: Exclude a file the words if any of... more

people

Why I'm getting CS1012: "Too many characters in character literal" and CS0019?

When trying to upload something to Imgur, I have to put an Authorization in. I do it with WebRequest.Headers but it gives me three errors. 2 times CS1012 error Too many...
Jon Skeet
people
quotationmark

You're trying to use single quotes for string literals - that's invalid in C#. Single quotes are for character literals (char). You need double quotes for string literals. You also need parentheses for a method... more

people