. C # Certification Exam Questions compilation: The first unit: 1,11 second unit: 1,11

Source: Internet
Author: User
Tags key string

First Unit 1, 11

Long time no different or almost forget, let us together to understand what is different or

This, inadvertently reminds me of some of the books on the Exchange worth of methods

I'm talking here. The Exchange method is not to use the third variable to exchange, but two

The implementation condition is C

a=100,b=10;
The first disadvantage may overflow if out of range
A=a+b; a=110,b=10
B=a-b; b=100,a=110
A=a-b; a=-10,b=100
b=100,a=10;
The second disadvantage may overflow if out of range
a=a*b;a=1000,b=10
b=a/b;b=100,a=1000
a=a/b;a=10,b=100
The third most ideal
For example: A=3, i.e. one (2); b=4, i.e. 100 (2).
To swap the values of a and B, you can use the following assignment statements:
A=a∧b;
B=b∧a;
A=a∧b;
a=011 (2) (∧) b=100 (2) (Result of A∧b, A has become 7)
a=111 (2) (∧) b=100 (2) (Result of B∧a, B has become 3)
b=011 (2) (∧) a=111 (2) (Result of A∧b, A has become 4)
A=100 (2)

a=10100001, b=00000110

A=a^b; //a=10100111

B=b^a; //b=10100001

A=a^b; //a=00000110

In fact, if you simply understand that the "same as 0" difference is 1

I can only say, boy, we have limited ability to do this.

Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Security.Cryptography;
Using System.Text;
Using System.Threading.Tasks;

Namespace Exercise 1._11
{
Class Program
{
static void Main (string[] args)
{
String S_text, s_key, s_result = null;
Char ch;
Console.WriteLine ("Please enter the original string:");
S_text = Console.ReadLine (). ToString ();
Console.WriteLine ("Please enter the key string");
S_key = Console.ReadLine (). ToString ();
if (S_text. Length!=s_key. Length)
{
Console.WriteLine ("Key string must be equal to the length of the original string");
Return Early termination procedure
}
for (int i=0;i<s_key. length;i++)
{
ch = s_text[i];
S_result + = (char) (ch ^ s_key[i]); Comrades, watch out. Cast to char type otherwise you get the wrong result
}

Console.WriteLine ("The string after encryption is:");
Console.WriteLine (S_result. ToString ());
Console.readkey ();
}
}
}

Second Unit 1, 11

Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Using System.Threading.Tasks;

Namespace Animal
{
Class Animal
{
private bool M_sex;
private string M_sound;
Public Animal ()
{
M_sound = "how ...";
M_sex = false;
}

Must not be preceded by parentheses ()

public bool Sex//For subclasses set the base class variable
{
get {return m_sex;}
set {m_sex = value;}
}
public string Sound
{
get {return m_sound;}
set {M_sound = value;}
}

Public virtual string Roan ()//virtual method
{
Return "Animal" +m_sound;
}
}
Class Dog:animal
{
Public Dog ()
{
Sex = true;
Sound = "Wow ...";
}
public override string Roan ()//override method
{
Return "Dog:" + sound;
}
}
Class Cat:animal
{
Public Cat ()
{
Sound = "Miaow ...";
}
public override string Roan ()
{

Return "Cat:" +sound;

}
}
Class Cow:animal
{
Public Cow ()
{
Sound = "Moo ...";
}
public override string Roan ()
{
Return "Cow:" + sound;
}
}
Class Program
{
static void Main (string[] args)
{
Animal Animal;
Animal = new Dog ();
Console.WriteLine (Animal. Roan ());
Animal = new Cat ();
Console.WriteLine (Animal. Roan ());
Animal = new Cow ();
Console.WriteLine (Animal. Roan ());
Console.read ();
}
}
}

. C # Certification Exam Questions compilation: The first unit: 1,11 second unit: 1,11

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.