楼主: 吕涛
2244 24

【独家发布】C# 4.0 How-To [推广有奖]

  • 0关注
  • 2粉丝

博士生

14%

还不是VIP/贵宾

-

TA的文库  其他...

加拿大房地产经济

威望
0
论坛币
124284 个
通用积分
0.8484
学术水平
10 点
热心指数
9 点
信用等级
7 点
经验
2167 点
帖子
129
精华
1
在线时间
16 小时
注册时间
2016-8-11
最后登录
2017-10-4

相似文件 换一批

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
  1. Book Description
  2. Need fast, robust, efficient code solutions for Microsoft C# 4.0? This book delivers exactly what you're looking for. You'll find more than 200 solutions, best-practice techniques, and tested code samples for everything from classes to exceptions, networking to XML, LINQ to Silverlight. Completely up-to-date, this book fully reflects major language enhancements introduced with the new C# 4.0 and .NET 4.0. When time is of the essence, turn here first: Get answers you can trust and code you can use, right now!
  3. Book Details
  4. Publisher:        SAMS Publishing
  5. By:        Ben Watson
  6. ISBN:        978-0-672-33063-6
  7. Year:        2010
  8. Pages:        672
  9. Language:        English
  10. File size:        7.5 MB
  11. File format:        PDF
复制代码

本帖隐藏的内容

C# 4.0 How-To.pdf (5.14 MB, 需要: 10 个论坛币)

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:How Enhancement Silverlight Description Networking everything networking techniques Microsoft efficient

本帖被以下文库推荐

沙发
吕涛 发表于 2016-8-13 22:24:53 |只看作者 |坛友微信交流群
  1. Search Text
  2. Scenario/Problem: You need an advanced text search where you can find
  3. patterns.
  4. Solution: Using regular expressions gives you the power to find complex patterns
  5. in text. .NET’s regular expression classes can be found in the System.Text.
  6. RegularExpressions namespace. A text search in its most fundamental form looks
  7. like this:
  8. string source = “We few, we happy few, we band of brothers...”;
  9. Regex regex = new Regex(“we”);
  10. MatchCollection coll = regex.Matches(source);
  11. foreach (Match match in coll)
  12. {
  13. Console.WriteLine(“\t\”{0}\” at position {1}”,
  14. match.Value.Trim(), match.Index);
  15. }
  16. Here’s the output:
  17. “we” at position 8
  18. “we” at position 22
  19. A
复制代码

使用道具

藤椅
吕涛 发表于 2016-8-13 22:26:38 |只看作者 |坛友微信交流群
  1. Extract Groups of Text
  2. Scenario/Problem: You need to extract portions of text into named groups.
  3. Suppose you have a file that looks like this:
  4. 1234 Cherry Lane, Smalltown, USA
  5. 1235 Apple Tree Drive, Smalltown, USA
  6. 3456 Cherry Orchard Street, Smalltown, USA
复制代码

  1. Solution: Let’s extract all the street names:
  2. string file =
  3. “1234 Cherry Lane, Smalltown, USA” + Environment.NewLine +
  4. “1235 Apple Tree Drive, Smalltown, USA” +
  5. Environment.NewLine +
  6. “3456 Cherry Orchard Street, Smalltown, USA” +
  7. Environment.NewLine;
  8. Regex regex = new Regex(“^(?<HouseNumber>\\d+)\\s*(?<Street>
  9. ➥[\\w\\s]*), (?<City>[\\w]+),
  10. ➥ (?<Country>[\\w\\s]+)$”, RegexOptions.Multiline);
  11. MatchCollection coll = regex.Matches(file);
  12. foreach (Match m in coll)
  13. {
  14. string street = m.Groups[“Street”].Value;
  15. Console.WriteLine(“Street: {0}”, street);
  16. }
  17. The following output is produced:
  18. Street: Cherry Lane
  19. Street: Apple Tree Drive
  20. Street: Cherry Orchard Street
复制代码

使用道具

板凳
吕涛 发表于 2016-8-13 22:28:41 |只看作者 |坛友微信交流群
  1. Convert a String to Bytes (and Vice Versa)
  2. Scenario/Problem: You need to convert text to and from a binary format.
  3. Solution: The System.Text namespace defines a number of classes that help you
  4. work with textual data. To convert to and from bytes, use the Encoding class.
  5. Although it is possible to create your own text-encoding scheme, usually you will
  6. use one of the pre-created static members of the Encoding class, which represent
  7. the most common encoding standards, such as ASCII, Unicode, UTF-8, and so on.
  8. The GetBytes() method will get the appropriate byte representation:
  9. string myString = “C# Rocks!”;
  10. byte[] bytes = Encoding.ASCII.GetBytes(myString);
  11. If you were to print out the string and the bytes, it would look like this:
  12. Original string: C# Rocks!
  13. ASCII bytes: 43-23-20-52-6F-63-6B-73-21
  14. Using Encoding.Unicode, it would look like this:
  15. Unicode bytes: 43-00-23-00-20-00-52-00-6F-00-63-00-6B-00-73-00-21-00
  16. To convert back, use Encoding.GetString() and pass in the bytes:
  17. string result = Encoding.ASCII.GetString(bytes);
  18. This is all simple enough, but consider the string “C# Rocks!”. The music note has
  19. no ASCII equivalent. This character will be converted to a question mark (?) if you
  20. convert to a byte format with no valid encoding, as in this example:
  21. string myString = “C# Rocks! ”;
  22. byte[] bytes = Encoding.ASCII.GetBytes(myString);
  23. string result = Encoding.ASCII.GetString(bytes);
  24. Console.WriteLine(“Round trip: {0}->{1}->{2}”,
  25. myString,
  26. BitConverter.ToString(bytes),
  27. result);
复制代码

使用道具

报纸
Lisrelchen 发表于 2016-8-13 22:35:17 |只看作者 |坛友微信交流群
  1. Compare Strings Correctly
  2. Scenario/Problem: You need to compare two localized strings. A localized
  3. string is any string that the users see that may have been translated into their
  4. local language.
  5. Solution: Always take culture into account and use the functionality provided in the
  6. .NET Framework. There are many ways to compare strings in C#. Some are better
  7. suited for localized text because strings can seem equivalent while having different
  8. byte values. This is especially true in non-Latin alphabets and when capitalization
  9. rules are not what you assume.
  10. Here is a demonstration of the issue:
  11. string a = “file”;
  12. string b = “FILE”;
  13. bool equalInvariant =
  14. string.Compare(a, b, true, CultureInfo.InvariantCulture) == 0;
  15. bool equalTurkish =
  16. string.Compare(a, b, true,
  17. CultureInfo.CreateSpecificCulture(“tr-TR”)) == 0;
  18. Console.WriteLine(“Are {0} and {1} equal?”,a,b);
  19. Console.WriteLine(“Invariant culture: “ +
  20. (equalInvariant ? “yes” : “no”));
  21. Console.WriteLine(“Turkish culture: “ +
  22. (equalTurkish ? “yes” : “no”));
复制代码

使用道具

地板
quetal 发表于 2016-8-13 22:48:53 |只看作者 |坛友微信交流群
Thanks for sharing!

使用道具

7
gdouxxm 发表于 2016-8-14 01:28:35 |只看作者 |坛友微信交流群
谢谢分享

使用道具

8
oyjy1986 在职认证  发表于 2016-8-14 01:43:22 来自手机 |只看作者 |坛友微信交流群
Take a look

使用道具

9
h050915 在职认证  发表于 2016-8-14 06:39:12 来自手机 |只看作者 |坛友微信交流群
谢分享

使用道具

10
bbyyss007 发表于 2016-8-14 07:00:58 |只看作者 |坛友微信交流群
好书,多谢楼主。。

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-5-1 07:56