Do I suppose static methods should not be written as the first fragment, or am I mistaken?
public static class ExtensionClass { private static SomeClass object1; private static StringBuilder sb; private static string DoSomething() { sb.AppendLine(object1.SomeValue); } public static string ExtensionMethod(this HtmlHelper helper, SomeClass _object1) { object1 = _object1; sb = new StringBuilder(); DoSomething(); return sb.ToString(); } }
So, I came up with this:
public static class ExtensionClass { private static string DoSomething(ref StringBuilder _sb,SomeClass object1) { _sb.AppendLine(object1.SomeValue); } public static string ExtensionMethod(this HtmlHelper helper, SomeClass _object1) { SomeClass object1 = _object1; StringBuilder sb = new StringBuilder(); DoSomething(ref sb,_object1); return sb.ToString(); }
}
Is this last snippet multithreaded safe? This should be an extension method, so it cannot be non-stationary. Or is there a better way to skip a non-static object in a static method?
, , . - HtmlHelper SomeClass, ExtensionMethod , . ExtensionMethod StringBuilder ( ), ExtensionMethod StringBuilders, .
, . , Thread A ExtensionMethod, Thread B ExtensionMethod, Thread A , sb , StringBuilder. , A , , A B StringBuilder !
sb
Source: https://habr.com/ru/post/1727104/More articles:Recompile Vim for pythoncomplete # Fill in the modules * other * than the standard library? - pythonOpening a file with the appropriate program - winapiLanguages ββwith direct compatibility C - c ++Network Reduction (Java) - javaCan we "not override a specific method ..." compile a temporary error in the implementation of the interfaces? - javaCSS selector style - cssCustom Validation Messages for Authlogic Session Model - ruby-on-railshttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1727107/what-happens-to-unicode-in-a-systemdatasqlcommand&usg=ALkJrhhvo1_b43zIY6I6RCYPwp0YeJukXQPython qt syntax error - pythonHow to sort characters of sections other than the "COMMON" section? - cAll Articles