Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.41 KB | None | 0 0
  1. public class Foo
  2. {
  3. public void Bar(IEnumerable x);
  4. }
  5.  
  6. public class Foo
  7. {
  8. public void Bar(IEnumerable x);
  9. public void Bar(ICloneable x);
  10. }
  11.  
  12. new Foo().Bar(new int[0]);
  13.  
  14. public class Foo
  15. {
  16. public static implicit operator int ();
  17. }
  18.  
  19. public class Foo
  20. {
  21. public static implicit operator int ();
  22. public static implicit operator float ();
  23. }
  24.  
  25. void Bar(int x);
  26. void Bar(float x);
  27. Bar(new Foo());
  28.  
  29. public class Foo
  30. {
  31. }
  32.  
  33. public class Foo
  34. {
  35. public void Bar();
  36. }
  37.  
  38. public static class FooExtensions
  39. {
  40. public void Bar(this Foo foo);
  41. }
  42.  
  43. new Foo().Bar();
  44.  
  45. public static class Foo
  46. {
  47. public static void bar(int i);
  48. }
  49.  
  50. public static class Foo
  51. {
  52. public static bool bar(int i);
  53. }
  54.  
  55. Foo.bar(13);
  56.  
  57. public void Foo(int a) { }
  58.  
  59. public void Foo(int a, string b = null) { }
  60.  
  61. Foo(5);
  62.  
  63. class Foo
  64. {
  65. public virtual void Bar() {}
  66. public virtual void Baz() {}
  67. }
  68.  
  69. class FooBase
  70. {
  71. public virtual void Bar() {}
  72. }
  73.  
  74. class Foo : FooBase
  75. {
  76. public virtual void Baz() {}
  77. }
  78.  
  79. // C++/CLI
  80. ref class Derived : Foo
  81. {
  82. public virtual void Baz() {{
  83.  
  84. // Explicit override
  85. public virtual void BarOverride() = Foo::Bar {}
  86. };
  87.  
  88. interface IFoo
  89. {
  90. void Bar();
  91. void Baz();
  92. }
  93.  
  94. interface IFooBase
  95. {
  96. void Bar();
  97. }
  98.  
  99. interface IFoo : IFooBase
  100. {
  101. void Baz();
  102. }
  103.  
  104. class Foo : IFoo
  105. {
  106. void IFoo.Bar() { ... }
  107. void IFoo.Baz() { ... }
  108. }
  109.  
  110. (new Foo()).Bar();
  111.  
  112. public enum Foo
  113. {
  114. Bar,
  115. Baz
  116. }
  117.  
  118. public enum Foo
  119. {
  120. Baz,
  121. Bar
  122. }
  123.  
  124. Foo.Bar < Foo.Baz
  125.  
  126. public class Foo
  127. {
  128. }
  129.  
  130. public class Foo
  131. {
  132. public void Frob() {}
  133. }
  134.  
  135. class Bar
  136. {
  137. public void Frob() {}
  138. }
  139.  
  140. class Program
  141. {
  142. static void Qux(Action<Foo> a)
  143. {
  144. }
  145.  
  146. static void Qux(Action<Bar> a)
  147. {
  148. }
  149.  
  150. static void Main()
  151. {
  152. Qux(x => x.Frob());
  153. }
  154. }
  155.  
  156. public class Foo : IEnumerable
  157. {
  158. public IEnumerator GetEnumerator();
  159. }
  160.  
  161. public class Foo : IEnumerable
  162. {
  163. IEnumerator IEnumerable.GetEnumerator();
  164. }
  165.  
  166. new Foo().GetEnumerator(); // fails because GetEnumerator() is no longer public
  167.  
  168. public class Foo : IEnumerable
  169. {
  170. IEnumerator IEnumerable.GetEnumerator() { yield return "Foo"; }
  171. }
  172.  
  173. public class Foo : IEnumerable
  174. {
  175. public IEnumerator GetEnumerator() { yield return "Foo"; }
  176. }
  177.  
  178. class Bar : Foo, IEnumerable
  179. {
  180. IEnumerator IEnumerable.GetEnumerator() // silently hides base instance
  181. { yield return "Bar"; }
  182. }
  183.  
  184. foreach( var x in new Bar() )
  185. Console.WriteLine(x); // originally output "Bar", now outputs "Foo"
  186.  
  187. Public Class Foo
  188. Public Shared Bar As String = ""
  189. End Class
  190.  
  191. Public Class Foo
  192. Private Shared _Bar As String = ""
  193. Public Shared Property Bar As String
  194. Get
  195. Return _Bar
  196. End Get
  197. Set(value As String)
  198. _Bar = value
  199. End Set
  200. End Property
  201. End Class
  202.  
  203. Foo.Bar = "foobar"
  204.  
  205. Imports System
  206. Imports Api.SomeNamespace
  207.  
  208. Public Class Foo
  209. Public Sub Bar()
  210. Dim dr As Data.DataRow
  211. End Sub
  212. End Class
  213.  
  214. namespace SomeNamespace {
  215. public class Foo {
  216. public static void Bar(string x) {
  217. ...
  218. }
  219. }
  220. }
  221.  
  222. namespace SomeNamespace {
  223. public class Foo {
  224. public static void Bar(string y) {
  225. ...
  226. }
  227. }
  228. }
  229.  
  230. Api.SomeNamespace.Foo.Bar(x:"hi"); //C#
  231. Api.SomeNamespace.Foo.Bar(x:="hi") 'VB
  232.  
  233. namespace SomeNamespace {
  234. public class Foo {
  235. public static void Bar(string x) {
  236. ...
  237. }
  238. }
  239. }
  240.  
  241. namespace SomeNamespace {
  242. public class Foo {
  243. public static void Bar(string x) {
  244. ...
  245. }
  246. public static void Bar(ref string x) {
  247. ...
  248. }
  249. }
  250. }
  251.  
  252. Api.SomeNamespace.Foo.Bar(str)
  253.  
  254. namespace SomeNamespace {
  255. public class Foo {
  256. public int Bar;
  257. }
  258. }
  259.  
  260. namespace SomeNamespace {
  261. public class Foo {
  262. public int Bar { get; set; }
  263. }
  264. }
  265.  
  266. FooBar(ref Api.SomeNamespace.Foo.Bar);
  267.  
  268. protected void Something<T>() where T : Class2 { }
  269.  
  270. protected class Class3 : Class2 { }
  271. protected void Something<T>() where T : Class3 { }
  272.  
  273. public int MyMethod(int mandatoryParameter, int optionalParameter = 0)
  274. {
  275. return mandatoryParameter + optionalParameter;
  276. }
  277.  
  278. public int MyMethod(int mandatoryParameter, int optionalParameter)
  279. {
  280. return mandatoryParameter + optionalParameter;
  281. }
  282.  
  283. public int MyMethod(int mandatoryParameter)
  284. {
  285. return MyMethod(mandatoryParameter, 0);
  286. }
  287.  
  288. public int CodeNotDependentToNewVersion()
  289. {
  290. return MyMethod(5, 6);
  291. }
  292.  
  293. public int CodeDependentToNewVersion()
  294. {
  295. return MyMethod(5);
  296. }
  297.  
  298. public interface IFoo
  299. {
  300. void Test();
  301. }
  302.  
  303. public class Bar
  304. {
  305. IFoo GetFoo() { return new Foo(); }
  306. }
  307.  
  308. public interface IFooNew // Of the exact same definition as the (old) IFoo
  309. {
  310. void Test();
  311. }
  312.  
  313. public class Bar
  314. {
  315. IFooNew GetFoo() { return new Foo(); }
  316. }
  317.  
  318. new Bar().GetFoo().Test(); // Binary only break
  319. IFoo foo = new Bar().GetFoo(); // Source and binary break
  320.  
  321. public static class Foo
  322. {
  323. public static void Bar(string x);
  324. }
  325.  
  326. public static class Foo
  327. {
  328. public void Bar(this string x);
  329. }
  330.  
  331. using static Foo;
  332.  
  333. class Program
  334. {
  335. static void Main() => Bar("hello");
  336. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement