Paste: MSDN Interview with C # programming IV

Source: Internet
Author: User
Tags foreach arrays error handling exception handling finally block web services win32 microsoft c
Programming ROBERT HESS: As a standard for loop?

JEFFREY RICHTER: Yes, as a standard for loop. So sometimes in the end, it does more work than I thought. Using foreach is quite common, and having it is really cool.

ROBERT HESS: I guess you should have put a counter there too, but that would completely make foreach useless.

JEFFREY RICHTER: Yes, that's right.

ROBERT HESS: So, what other cool features do you think C # has, to let the audience say, "Well, that's the language I'm going to choose?"

JEFFREY RICHTER: Well, as Anders pointed out earlier, C # is completely component-based, where there are events, interfaces, and attributes, they are first-class citizens, so there is no sliding bar, no sliding bar properties, and so on any similar things. People born in C # should be familiar with exception handling, because when an error is encountered, an error handler in the framework in the base Class library is invoked. So I wrote a small piece of code on the screen to demonstrate how to do the proper error handling. I have a try block, and again, you should be aware that there is no slide bar in front of the try word because it is in the first class in the C # language. I'm new to a file stream object, which is one way to open a file on a disk. In double quotes, I give the path name of the file we want to open.
Using System;
Using System.IO;

public class App {
public static void Main () {
FileStream fs = null;
try {
FS = new FileStream (@ "C:\NotThere.txt", FileMode.Open);
}
catch (Exception e) {
Console.WriteLine (E.message);
}
finally {
if (fs!= null) fs. Close ();
}
}
}


ROBERT HESS: Wait, that's a mistake, isn't it?

JEFFREY RICHTER: No, that's exactly what I want to point out. Because C # has a very cool feature, you can prefix the string with an @ symbol, which allows us to switch to the literal string (verbatim string, which is true, without any escape characters), where only the SLR slash "\" is allowed instead of the double backslash "\". And long path is a very common C + + programming error, people with backslashes instead of double backslash, the file can not be opened correctly. In this case the application plus "\ n" means that the line is to be wrapped. So, this is really an ingenious feature. Unlike a file stream, because people are familiar with the CreateFile function of Win32, when the function cannot open a file, it returns an invalid handle value, or a return of 1 means failure. In the. NET framework, an exception is thrown when I attempt to open a file that does not exist, so I set up a catch block here to try to catch the exception, which is a very simple catch block that only prints the information out of the screen to see what might have been done, And then I set up a finally block where the code is sure to execute, so if I have many lines of code in the try block that really involve file operations, after opening the file, the finally block executes and closes the file explicitly at the end. This is really a very ingenious feature, Win32 even C + + did not have, it can make try,catch and finally seamless, really count up, this operation we have never met before.

ROBERT HESS: I think it's very important for people to make error handling when an application becomes more and more complex, and there may be a lot of opportunities for errors when attempting to create files or perform similar operations. Especially when using other people's objects and things like that.
So does this mean that when you write your C # application, you must ensure that both the function and the method set the exception correctly and throw an exception so that people can catch it?

JEFFREY RICHTER: Well, absolutely. Good programming Paradigm: When writing a function, you must validate all incoming arguments, and if any one of the parameters is not required, you should explicitly throw an exception, and a large number of exception classes are defined in the base Class library, so you can easily use one of them. But you also have the ability to define your own exception classes, perhaps, to find the database, customer (customer), but it seems that they did not find their name, so you can create your own customer exception, and in the code somewhere to throw it.

ROBERT HESS: You may use the name of a customer as a damaged customer name ...

JEFFREY RICHTER: Yes, maybe so. If it's "Robert," that's the exception you've been trying to throw.


ROBERT HESS: So, how do you think C # will evolve as a programming language? What do you think of your customers when they take part in the training?

JEFFREY RICHTER: Well, I really think it will get a lot of momentum. I have said that last year I have been specialized in C # programming, and occasionally use C + +, but now rarely used, and I believe that many VB programmers will also turn to this language, because C # is more suitable for the common language runtime. So, I really think it's going to get a lot of momentum and really get reused. In my training class, it seems that everyone likes it, in fact, some people say they attend the training course, only because it has a C # programming class, but soon they are pleased to find that the curriculum also covers the framework and class library.


ROBERT HESS: So, when it comes to the. NET framework and class libraries, what do you think about them and how do they help the application develop?

JEFFREY RICHTER: I think the platform is performing well. I've been using the entire platform for a year now and I've been developing a project for Microsoft to showcase many of Microsoft's technologies. I work with another guy, his name is Tom, we're going to meet in the morning, we're going to talk on the Whiteboard, and then ... Here's the performance we're going to add today, and we'll talk about it for a while, and we're going to say that this is our goal at the end of the day, and we usually have to finish it before lunch. We always exceed the task.

ROBERT HESS: Do you think the combination of C # and. NET will help you get your work done?

JEFFREY RICHTER: Oh, of course. No doubt, because all the tests have been completed. All the tests-how do we expose this thing, can we make this a method, can we put it in a DLL, can we make it into a variable COM object, what kind of interface we should have. All of these questions relate to how you connect these and pass pointers, keep them connected so you can sync, so you can notify them by keeping up with others, all of which have just been introduced to the platform. So, from beginning to end, we are willing to work one hours, we have to finish some work, we will ... and then we have to sit back and start adding something else. How productive we are is, indeed, unbelievable, and equally fun. We did add amazing graphics and alpha process colors (blending) and all kinds of things that we've never dealt with alpha-color before. I've worked on graphic images, but it's been a long time. With the System.Drawing statements in the corresponding namespaces, we were able to construct and overwrite and alpha process the images, and then return the images from our Web server to any client running on any machine, not even a Windows machine.

ROBERT HESS: I think it brings a good choice. So far, we've been talking about the development of applications using C # and the. NET framework, and I learned that you were a real application designer, writing Windows applications and standard GUI programs. Surprisingly, the web appears, so everyone is thinking about writing a Web application or writing an html-based application that runs inside the browser. But now, in a nutshell, you're talking about a Windows graphics application with this alpha synthesis standard, and also about accessing the web and returning it to other systems in the appropriate format. So WIN32 application developers like you and I have a traditional application development environment and a new Web application with. NET mix what is the view?

JEFFREY RICHTER: Well, what I'm actually doing is this particular thing, it's not a WIN32 graphics application, it's a Web form, a Web form at random.
ROBERT HESS: So is it not even a traditional Windows application? It sounds very much like AH.
JEFFREY RICHTER: Well, what is it really? In fact, it has a more complex system than the traditional Win32 program. It's actually a Web service, and I think it's one of the first public Microsoft Web Services, which is free, so I'll give you the URL address. So anyone can go there to fiddle with, this address is teraserver. Microsoft.NET.
ROBERT HESS: Oh, I'll put this address in the back of this record so that you can click here to visit.
JEFFREY RICHTER: There are many advertising campaigns for Microsoft technologies, including Windows Datacenter, SQL 2000, IIS, ASP.net,. NET Frameworks, Web services, and Web Forms. The information is on that website. There is a teraserver Web service with image information, which displays images and headings in stereoscopic topographic maps and regular photographs. And we also have a census (census) service, so we can enter latitude, longitude and so on, then get the corresponding city name and the population living in the area. We also have a landmark (landmark) service, which provides a rectangular area calibrated with latitude and longitude to find hospitals and schools in the area. Therefore, they are three separate Web services. They could have been implemented by different companies, but we actually did. We then wrote a Web Forms application that could have been written by any company, but this time it was written by us to make sense of the concept, sending information to these three different Web services, getting header information from Teraserver, and getting landmark information from the landmark server, Then we can load the information into the map.

ROBERT HESS: Use alpha process color.


JEFFREY RICHTER: Well, yes, use alpha process color. The information is then sent back to the Web form and sent back to customers running on any machine. We can even add such a feature that when the mouse moves over something, the cue tool will appear and tell you the appropriate school name and hospital name on the page. The power of this paradigm is simply unbelievable. In fact, the customer can be any machine running any operating system, and we use the Windows 2000 GDI + performance on the server to handle alpha process color, and such advanced graphics operations, but we only send the bitmap (bit map) back to the customer, I think again, its powerful, The high productivity is simply unbelievable. And I've learned that many applications are moving in this direction.


ROBERT HESS: So you really like the entire web model of a Web application.
JEFFREY RICHTERLike

ROBERT HESS: Even if you are a traditional developer of Windows applications.
JEFFREY RICHTERYes

ROBERT HESS: You are now moving in this direction.

JEFFREY RICHTER: Yes, I have made up my mind. The program should be able to run anywhere and work on the server. All of this makes up the so-called Distributed System (distributedness), where servers can be located in Santai different machines, oh, the SQL Server that maintains all this information can also be another machine, Web Forms servers are located on different machines, And they can be finely tuned by different companies to use these materials at will, and they feel that they are suitable for generating content-rich applications that run anywhere that can be accessed by the Internet. It's unbelievable, it's hard to believe!


ROBERT HESS: Some signs tell me that all these things leave you with a symptom.


JEFFREY RICHTER: Yes, a little.


ROBERT HESS: Well, for the audience's eager developers, they want to plunge into C # and start writing some. NET applications, what do you really need to know before they take the first step? What do you think is the last thing to emphasize?

JEFFREY RICHTER: I think one of the biggest problems that these developers will face is that they have to recognize that the C # language reveals the performance in runtime and base class libraries, and perhaps in time they learn from experience. And a lot of people will be watching C #, and maybe they'll try or focus on something else. NET language, there may be attempts to do something that is not supported by these languages, and then of course it is not possible. For example: In C #, all arrays are based on 0 by default and are started with a 0 index (subscript). However, the common language runtime supports arrays with any bottom and upper bounds. An array is constructed in the base Class library that has the set up and down bounds. But C # naturally does not provide these features. So you have to learn, over time, to understand what it is, many times you may be able to use other languages, or to access the underlying system of the language, which is located at the top of the runtime, and for some reason the designer won't let us access the underlying system.


ROBERT HESS: It seems that way, by understanding all of the performance at the bottom of the runtime, you can then give these performance maps (map) to any language you are currently using in order to see if they provide the functionality you need. For example, when I write a Web page, I always write it in pure HTML, because I know what its function is. But if I have to write in FrontPage, I know that FrontPage has its own format (mindset), related to the display of the Web page, and I know what it offers and what it doesn't offer. Occasionally I also have to turn to pure HTML and add something or other tools in this way, which seems to be the same thing.


JEFFREY RICHTER: Sometimes these functions are also available in C #, but appear in different names, for example, in the Formula language library, virtual functions are called family. So to create a virtual function in C #, you will qualify it with protected. Yes, or no protected, but the protected in C # is equivalent to the family in the common language runtime. Oh, it's confusing. Look, even I was confused.


ROBERT HESS: So the basic idea sounds like it's about understanding the tools you're using, and how they're running at the bottom of the. NET Framework. Well, thank you very much Jeffery, and I am very honored to talk with you, I will find a time to invite you back to participate in this "show" program.


JEFFREY RICHTER: Yes, I'd love to, thank you.


ROBERT HESS: This is what programmers Jeffery to C # and the. NET Framework. He provides you with some good information to help you understand the new development area. He talked about a lot of URL addresses and source code examples and similar data. I promise to put them behind this record, so keep watching the rest of the show and see what else you have.
...... (Omit conversations that have nothing to do with C #)




Conclusion


ROBERT HESS:Thank you for attending another issue of MSDN show. This time we discussed the problem of programming with C #.

ERICA wiechers:In the next issue of MSDN Show, we will talk about soap and how it is integrated into the. NET programming system.

ROBERT HESS:By then, we will meet again on the Internet.


Links to more information

Microsoft C # data:
C # Overview and introduction (Overview and Introduction to c#,http://msdn.microsoft.com/vstudio/nextgen/technology/csharpintro.asp)

C # Language Specification (C # Language specification,http://spectre/test/library/default.asp?) url=/library/dotnet/csspec/vclrfcsharpspec_start.htm)

Voice of MSDN: Deep into C # column (MSDN voices:deep C # column,http://msdn.microsoft.com/voices/deepc.asp)
A regular column, where Bobby Schmidt shares his views and insights on using C #.

Msdn. NET Developer Center (MSDN Developer Center for. net,http://msdn.microsoft.com/net/)
Provide more relevant. NET technology development data.

C # newsgroups (C # newsgroup,news://msnews.microsoft.com/microsoft.public.dotnet.languages.csharp)
Talk to each other and consult with people who are learning to use C #.

Information on the Jeffrey Richter conversation:
code example (sample code: Unknown address)
Book: Programming Applications for Microsoft Windows
Programming Server-side applications for Windows
(written with Jason Clark)
Wintellect(http://www.wintellect.com/,)
Jeffrey training and consulting firm.
terraserver.net(http://terraserver.microsoft.net/)
Jeffrey helps to write mapping services.
Jeffrey Richter's homepage (http://www.jeffreyrichter.com/)

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.