- 1
- 2
- 3
- 4
- 5
switch (!_data.Provider)
{
case true: _currentState = states.DT2F; break;
case false: _currentState = states.DT2P; break;
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+139
switch (!_data.Provider)
{
case true: _currentState = states.DT2F; break;
case false: _currentState = states.DT2P; break;
}
Проверка двух условий
+138
private static T GetElementValue<T>(this XmlElement elm, string elementName, T defaultValue = default(T), bool throwIfError = false, bool throwIfMissing = false)
where T : IConvertible
{
string val = GetElementValue(elm, elementName);
if (string.IsNullOrEmpty(val) == false)
{
if (typeof(T) == typeof(string))
{
return (T)(object)val;
}
if (typeof(T) == typeof(bool))
{
return (T)(object)(val == "1");
}
try
{
if (typeof(T) == typeof(DateTime))
{
return (T)(object)DateTime.Parse(val, System.Globalization.CultureInfo.InvariantCulture); ;
}
return (T)Convert.ChangeType(val, typeof(T), CultureInfo.InvariantCulture);
}
catch (Exception exc)
{
if (throwIfError)
throw exc;
}
}
if (throwIfMissing)
throw new ArgumentNullException("The parameter '" + elementName + "' is missing");
return defaultValue;
}
Используем Generics по-фэншую!
+104
283: public static IList<Service> MultithreadHostCheckImplementation(string userName, string userPassword, string clientName, string serviceName, int iImplType, string samsungAccessToken,
bool checkSamsungAccountInCustomProps,string clientSoftware,string decryptedInstallKey,
out Guid userRefId, out string subscriptionId, out bool isIPhoneUser, out string serviceHostHeader)
{
//....
783: }
Русский код. Ровно 500 строк отборного!
+137
private string ExtractNodeValue(string text, string nodeName)
{
string result = string.Empty;
int slength = ("<" + nodeName + ">").Length;
int sindex = text.IndexOf("<" + nodeName + ">");
int eindex = text.IndexOf("</" + nodeName + ">");
if (sindex > 0 && eindex > 0)
result = text.Substring(sindex + slength, eindex - sindex - slength);
return result;
}
string request = string.Format("http://maps.google.com/maps/geo?ll={0},{1}&hl=en&output=xml&key=abcdefg", location.latitude, location.longitude);
Logger.Log(request);
HttpWebRequest httprequest = (HttpWebRequest)WebRequest.Create(request);
WebResponse responce = httprequest.GetResponse();
Stream str = responce.GetResponseStream();
XmlTextReader reader = new XmlTextReader(str);
reader.XmlResolver = null;
XmlDocument doc = new XmlDocument();
doc.Load(reader);
str.Close();
reader.Close();
XmlNodeList listResponse = doc.ChildNodes[1].ChildNodes[0].ChildNodes;
foreach (XmlNode nodePlace in listResponse)
{
if (nodePlace.Name == "Placemark")
{
string text = nodePlace.InnerXml;
string Country = ExtractNodeValue(text, "CountryName");
if ((this.DataContext.Countries.Count(x => x.Name == location.countryName) == 0 || string.IsNullOrWhiteSpace(location.countryName)) &&
!string.IsNullOrWhiteSpace(Country))
{
location.countryName = Country;
}
string Region = ExtractNodeValue(text, "AdministrativeAreaName");
if (this.DataContext.States.Count(x => x.AlphaCode == location.region || x.Name == location.region) == 0 &&
!string.IsNullOrWhiteSpace(Region))
{
location.region = Region;
}
string City = ExtractNodeValue(text, "LocalityName");
if (this.DataContext.Cities.Count(x => x.Name == location.city) == 0 &&
!string.IsNullOrWhiteSpace(City))
{
location.city = City;
}
break;
}
}
отличный парсиг xml.
+102
...
while (GetRateStumpNew(_rateStumps, ddtdDateBegin, dDateEnd, out sstrRateStumpsNew,
out ddtDateEditrateStumps, out ddouRateStumpsNew))
{
//если хоть раз сюда зашло, то ставим флагец
isStumpForFirst = true;
//записываем дату
ddtdDateBegin = ddtDateEditrateStumps;
//если один раз зашли, то дальше можно не проверять
goto l1; //временно
}
l1:
...
Полный контроль над последовательностью выполнения кода
+141
public string Search(string title)
{
List<string> str1 = new List<string>();
string count = cmainlibrary.Count.ToString();
int counter = Convert.ToInt32(count);
int i = 0;
for ( i = 0; i < counter; i++)
{
string title_library = cmainlibrary[i].Title.ToString();
if (title.ToUpper().Contains(title_library. ToUpper()))
{
str1.Add(cmainlibrary[i].Title);
}
}
return str1[i];
}
Хотя я это выкладывал в коментариях к говнокоду #11830, решил повеселить народ отдельным постом.
Это реализация библиотеки книг. Метод должен искать список книг которые соответствуют title.
+127
while (true) {
Console.WriteLine(answer);
answer = process.StandardOutput.ReadLine();
}
Человеку нужно просто считывать команды (строки) из консоли. Делает через жопу.
+138
public void Delete(CommonType type)
{
label1:
Console.Write("Enter the title of the book: ");
string title = Console.ReadLine();
if (title == type.Title)
{
cmainlibrary.Remove(type);
Console.Write("Success");
Console.Read();
goto label1;
}
else
{
goto label1;
}
}
+136
// http://msdn.microsoft.com/en-us/library/dya2szfk%28v=VS.71%29.aspx
If x = True Then ' Compares x to the Boolean value True.
' Insert code to execute if x = True.
Else
' Insert code to execute if x = False.
End If
http://msdn.microsoft.com/en-us/library/dya2szfk%28v=VS.71%29.aspx
Учебник по языку, да
+133
string[] res = value.Split("$".ToCharArray(), StringSplitOptions.None);