C # Problem,

Source: Internet
Author: User

C # Problem,

1. Can there be attributes in the struct?

You can have attributes. Test code and.

In C #, we can use the following statement to convert a string s to an integer num 124

A.int num = Convert. ToInt32 (s );

B .int nym = Int32.Parse (s );

C.int num = s. ToInt (); (not allowed)

D.int num = int. Parse (s); (tested)

using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace Fraction{    public struct StructTest    {        private int x;        public int X        {            get { return x; }            set { x = value; }        }        public StructTest(int _x)        {            x = _x;        }    }    class Program    {        static void Main(string[] args)        {            StructTest str = new StructTest();            str.X = 1;            Console.WriteLine(str.X);            string s = "123";            int num1 = Convert.ToInt32(s);            int num2 = Int32.Parse(s);            //int num3 = s.ToInt();            int num4 = int.Parse(s);            Console.WriteLine("num1="+num1);            Console.WriteLine("num2="+num2);            //Console.WriteLine(num3);            Console.WriteLine("num4="+num4);            Console.Read();        }    }}

Property can be declared in class, struct, interface!

  Benefits of using attributes:

Read-only or write-only segments are allowed;

Fields can be verified during access;

Interface and implementation data can be different;

Replace the data in the interface.

  

2. parameter transfer method: pass by value or by reference. The parameter is not passed by location or by name.

3. LINQ query: LINQ to Object, LINQ to XML, and LINQ to ADO. NET include two independent technologies: LINQ to DataSet and LINQ to SQL.

You can query the data in arrays and other columns for LINQ to Object;

You can query the data in tables that can be queried by SQL for the LINQ to SQL statement;

You can query the labels of XML documents for LINQ to XML;

You can query data in DataSet by using LINQ to DataSet;

3. Form of delegation

F = delegate (int x) {return x + 1 ;};

F = x => x + 1;

  

Test code:

using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace Lambda{    class Program    {        static void Main(string[] args)        {            int sum = 0;            Func<int, int> f1 = x => 2 * x + 1;            Func<int, int, bool> f2 = (x, y) => x > y;            Func<string, int, string> f3 = (x, y) => x.Substring(y);            Func<int, int> f4 = (x) => sum += x;            Action a1 = () => { System.Console.WriteLine("HelloWorld"); };            Action <int> a2 = (x) => { System.Console.WriteLine(x); };            Action <bool> a3 = (x) => { System.Console.WriteLine(x); };            Action<string> a4 = (x) => { System.Console.WriteLine(x); };            for (int i = 1; i <= 10; i++ )            {                f4(i);            }            a2(sum);            a1();            a2(f1(1));            a3(f2(3, 5));            a4(f3("Zhengpengfei", 5));            System.Console.Read();        }    }}

4. the embedded types can be classes, structures, struct, enumeration, and delegation.

For details, see the PPT

5. Classes and struct, classes and interfaces, overloading and overriding, virtual and abstract methods, managed code and unmanaged code

  

6. Constants can be declared static (True)

In C #, the const and static variables cannot be modified simultaneously;

7. boxing: Convert the value type to the reference type;

Unboxing: Convert the reference type to the value type.

8. An interface member isImplementedOr _Inherited_ From a base class

The interface members are either defined by themselves or inherited from the parent class.

The interface cannot contain constants, fields, operators, constructors, destructor, any static members,Method implementation;

9. What is the difference between private assembly and public assembly?

Private assemblyIt can only be used by one application, stored in the application directory, and cannot be named or signed;

Public assemblyCan be used by the application, stored in the global assembly, must have a strong name, can sign

Strong naming includes four parts: AssemblyName, AssemblyVersion, AssemblyCultural attributes, Assembly.

10.Which of the following are correct ways to pass a parameter to a attribute?

1) By value 2) by reference 3) by position 4) by name

A 1, 2B 3, 4C 1, 2, 3, 4, D1, 2, 3

Related Article

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.