First of all, XNA also uses C# too so it's the same programming language. And although the underlying API might have some differences from DirectX, that has nothing to do with jumping, so the same tutorials or answers should apply here. Also, there are numerous ways to implement this, depending on a lot of factors. What I'll describe below is just one of the possibilities.
Basic Physics Requirements
First you need some basic physics variables and calculations on your update loop. In particular, you need position, velocity, and gravity defined, and your update loop should be doing something roughly similar to this (collision detection and response omitted for simplicity):
float positionX, positionY; // Position of the character
float velocityX, velocityY; // Velocity of the character
float gravity = 0.5f; // How strong is gravity
void Update(float time)
velocityY += gravity * time; // Apply gravity to vertical velocity
positionX += velocityX * time; // Apply horizontal velocity to X position
positionY += velocityY * time; // Apply vertical velocity to X position
Fixed Height Jump
Now the easiest way to implement a jump that always has the same height, no matter how long you press the key, is simply to change the vertical velocity once. This will make the character start rising, while gravity will automatically take care of bringing him down:
velocityY = -12.0f; // Give a vertical boost to the players velocity to start jump
Important You don't want to be able to start a jump if your character is not on the ground, so you'll need to add a check for that.
Variable Height Jump
But games like Mario and Sonic have a variable jump where the height of the jump depends on how long you press the button down. In this case you'll need to handle both pressing and releasing the jump key. You could add something like:
if(velocityY < -6.0f) // If character is still ascending in the jump
velocityY = -6.0f; // Limit the speed of ascent
Tweaking all of these values (i.e. the numbers like
-6.0f) in the code above you can change the feel of your jump, how high he jumps, how much momentum does he keep even after releasing the jump button, how fast he falls, etc.
Important Don't call these functions every frame. Call them only once when the key is pressed or released. Otherwise your character will fly instead of jump.
I have just created a quick example of the techniques described above, which you can try on your browser here (press mouse button to jump, release it midway to control the height of the jump). It's in JS but like I mentioned earlier, the language is irrelevant in this case.